From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq4kQ-0002EN-MH for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:26:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rq4kJ-0005cD-Ar for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:26:54 -0500 Received: from mout.perfora.net ([74.208.4.195]:55095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq4kJ-0005bu-5f for qemu-devel@nongnu.org; Wed, 25 Jan 2012 10:26:47 -0500 From: Michael Roth Date: Wed, 25 Jan 2012 09:26:21 -0600 Message-Id: <1327505186-18328-2-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1327505186-18328-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1327505186-18328-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 1/6] main-loop: Fix SetEvent() on uninitialized handle on win32 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com The __attribute__((constructor)) init_main_loop() automatically get called if qemu-tool.o is linked in. On win32, this leads to a qemu_notify_event() call which attempts to SetEvent() on a HANDLE that won't be initialized until qemu_init_main_loop() is manually called, breaking qemu-tools.o programs on Windows at runtime. This patch checks for an initialized event handle before attempting to set it, which is analoguous to how we deal with an unitialized io_thread_fd in the posix implementation. Signed-off-by: Michael Roth --- main-loop.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/main-loop.c b/main-loop.c index 692381c..62d95b9 100644 --- a/main-loop.c +++ b/main-loop.c @@ -164,7 +164,7 @@ static int qemu_signal_init(void) #else /* _WIN32 */ -HANDLE qemu_event_handle; +HANDLE qemu_event_handle = NULL; static void dummy_event_handler(void *opaque) { @@ -183,6 +183,9 @@ static int qemu_event_init(void) void qemu_notify_event(void) { + if (!qemu_event_handle) { + return; + } if (!SetEvent(qemu_event_handle)) { fprintf(stderr, "qemu_notify_event: SetEvent failed: %ld\n", GetLastError()); -- 1.7.4.1