From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7jfP-0006fg-Kw for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:16:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X7jfI-0000Al-Tp for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:16:03 -0400 Received: from mail.ispras.ru ([83.149.199.45]:47623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7jVS-0005W8-15 for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:05:46 -0400 From: Pavel Dovgalyuk Date: Thu, 17 Jul 2014 15:05:48 +0400 Message-ID: <20140717110548.8352.49400.stgit@PASHA-ISP> In-Reply-To: <20140717110153.8352.80175.stgit@PASHA-ISP> References: <20140717110153.8352.80175.stgit@PASHA-ISP> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH v2 41/49] tap-win32: destroy the thread at exit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, fred.konrad@greensocs.com This patch fixes resource leak caused by created thread which is not destroyed at exit. Signed-off-by: Pavel Dovgalyuk --- net/tap-win32.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/net/tap-win32.c b/net/tap-win32.c index 8aee611..efd1c75 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -99,6 +99,7 @@ typedef struct tap_win32_overlapped { HANDLE output_queue_semaphore; HANDLE free_list_semaphore; HANDLE tap_semaphore; + HANDLE hThread; CRITICAL_SECTION output_queue_cs; CRITICAL_SECTION free_list_cs; OVERLAPPED read_overlapped; @@ -625,8 +626,9 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle, *phandle = &tap_overlapped; - CreateThread(NULL, 0, tap_win32_thread_entry, - (LPVOID)&tap_overlapped, 0, &idThread); + tap_overlapped.hThread = CreateThread(NULL, 0, tap_win32_thread_entry, + (LPVOID)&tap_overlapped, + 0, &idThread); return 0; } @@ -643,9 +645,8 @@ static void tap_cleanup(NetClientState *nc) qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL); - /* FIXME: need to kill thread and close file handle: - tap_win32_close(s); - */ + TerminateThread(s->handle->hThread, 0); + CloseHandle(s->handle->handle); } static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size)