[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 15/25] block/linux-aio: fix memory and fd leak
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v3 15/25] block/linux-aio: fix memory and fd leak |
Date: |
Thu, 8 May 2014 16:34:48 +0200 |
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 <address@hidden>
---
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 7881f12..7d0325a 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1084,6 +1084,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.0
- [Qemu-devel] [PATCH v3 02/25] block: acquire AioContext in bdrv_*_all(), (continued)
- [Qemu-devel] [PATCH v3 02/25] block: acquire AioContext in bdrv_*_all(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 03/25] block: acquire AioContext in bdrv_drain_all(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 04/25] block: add bdrv_set_aio_context(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 05/25] blkdebug: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 07/25] curl: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 08/25] gluster: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 09/25] iscsi: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 14/25] block/raw-posix: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 15/25] block/linux-aio: fix memory and fd leak,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v3 16/25] block/raw-win32: create one QEMUWin32AIOState per BDRVRawState, Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 17/25] block/raw-win32: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 18/25] rbd: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 20/25] ssh: use BlockDriverState's AioContext, Stefan Hajnoczi, 2014/05/08
- [Qemu-devel] [PATCH v3 21/25] vmdk: implement .bdrv_detach/attach_aio_context(), Stefan Hajnoczi, 2014/05/08