[Spice-devel] [vdagent-win PATCH v4 11/19] Allocate _control_event and _stop_event just once
Frediano Ziglio
fziglio at redhat.com
Mon Jul 2 07:43:50 UTC 2018
Handle _control_event and _stop_event destruction in destructor.
Still allows to call VDAgent::run multiple time if needed.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
vdagent/vdagent.cpp | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 0672516..def3508 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -222,6 +222,8 @@ VDAgent::VDAgent()
VDAgent::~VDAgent()
{
+ CloseHandle(_stop_event);
+ CloseHandle(_control_event);
delete _log;
}
@@ -283,13 +285,18 @@ bool VDAgent::run()
return false;
}
}
- _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (!_control_event)
+ _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!_control_event) {
vd_printf("CreateEvent() failed: %lu", GetLastError());
cleanup();
return false;
}
- _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
+ ResetEvent(_control_event);
+
+ if (!_stop_event)
+ _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
+
memset(&wcls, 0, sizeof(wcls));
wcls.lpfnWndProc = &VDAgent::wnd_proc;
wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
@@ -336,8 +343,6 @@ bool VDAgent::run()
void VDAgent::cleanup()
{
- CloseHandle(_stop_event);
- CloseHandle(_control_event);
CloseHandle(_vio_serial);
}
--
2.17.1
More information about the Spice-devel
mailing list