Received: from eggs.gnu.org ([2001:4830:134:3::10]:49331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCpv9-0001cS-OZ for qemu-devel@nongnu.org; Thu, 31 Jul 2014 08:57:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCpv3-0006b0-M3 for qemu-devel@nongnu.org; Thu, 31 Jul 2014 08:57:23 -0400 Received: from mail.ispras.ru ([83.149.199.45]:54877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCpv3-0006an-BJ for qemu-devel@nongnu.org; Thu, 31 Jul 2014 08:57:17 -0400 From: Pavel Dovgalyuk Date: Thu, 31 Jul 2014 16:57:20 +0400 Message-ID: <20140731125719.1600.55885.stgit@PASHA-ISP.novsu.ac.ru> In-Reply-To: <20140731125321.1600.46604.stgit@PASHA-ISP.novsu.ac.ru> References: <20140731125321.1600.46604.stgit@PASHA-ISP.novsu.ac.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH v3 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, maria.klimushenkova@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, afaerber@suse.de, 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)