]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
block/linux-aio: fix memory and fd leak
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 8 May 2014 14:34:48 +0000 (16:34 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Wed, 4 Jun 2014 07:56:11 +0000 (09:56 +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 <stefanha@redhat.com>
block/linux-aio.c
block/raw-aio.h
block/raw-posix.c

index 7ff3897fec6cddf032b71b47679df7b49dca63fd..f0a2c087b28a8450c930e9367d78ebee5f83804f 100644 (file)
@@ -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);
+}
index 9a761eeadeb0d6298c61317f53c1bc728558b586..55e0ccc6ed5e987b8c9a9fb469e15bc079e597ea 100644 (file)
@@ -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);
index cce10a45a8ec80a7ea1ad0ab5d994bbfd95cb22a..ffdb1763f81a6bfe8c856fa52d4a716ed46cc08f 100644 (file)
@@ -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;