From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswn7-0004i3-Tt for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wswn1-0004SV-Nv for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:14:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswn1-0004SK-AV for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:14:47 -0400 From: Stefan Hajnoczi Date: Fri, 6 Jun 2014 18:13:37 +0200 Message-Id: <1402071243-16702-17-git-send-email-stefanha@redhat.com> In-Reply-To: <1402071243-16702-1-git-send-email-stefanha@redhat.com> References: <1402071243-16702-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 16/42] block/linux-aio: fix memory and fd leak List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi Hot unplugging -drive aio=native,file=test.img,format=raw images leaves the Linux AIO event notifier and struct qemu_laio_state allocated. Luckily nothing will use the event notifier after the BlockDriverState has been closed so the handler function is never called. It's still worth fixing this resource leak. Signed-off-by: Stefan Hajnoczi --- block/linux-aio.c | 8 ++++++++ block/raw-aio.h | 1 + block/raw-posix.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/block/linux-aio.c b/block/linux-aio.c index 7ff3897..f0a2c08 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -212,3 +212,11 @@ out_free_state: g_free(s); return NULL; } + +void laio_cleanup(void *s_) +{ + struct qemu_laio_state *s = s_; + + event_notifier_cleanup(&s->e); + g_free(s); +} diff --git a/block/raw-aio.h b/block/raw-aio.h index 9a761ee..55e0ccc 100644 --- a/block/raw-aio.h +++ b/block/raw-aio.h @@ -34,6 +34,7 @@ /* linux-aio.c - Linux native implementation */ #ifdef CONFIG_LINUX_AIO void *laio_init(void); +void laio_cleanup(void *s); BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque, int type); diff --git a/block/raw-posix.c b/block/raw-posix.c index cce10a4..ffdb176 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1087,6 +1087,11 @@ static void raw_close(BlockDriverState *bs) raw_detach_aio_context(bs); +#ifdef CONFIG_LINUX_AIO + if (s->use_aio) { + laio_cleanup(s->aio_ctx); + } +#endif if (s->fd >= 0) { qemu_close(s->fd); s->fd = -1; -- 1.9.3