qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH for-2.4 1/2] AioContext: avoid leaking BHs on cleanu


From: Stefan Hajnoczi
Subject: [Qemu-devel] [PATCH for-2.4 1/2] AioContext: avoid leaking BHs on cleanup
Date: Mon, 27 Jul 2015 17:33:38 +0100

BHs are freed during aio_bh_poll().  This leads to memory leaks if there
is no aio_bh_poll() between qemu_bh_delete() and aio_ctx_finalize().

Suggested-by: Paolo Bonzini <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
 async.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/async.c b/async.c
index 9a98a74..9fab4c6 100644
--- a/async.c
+++ b/async.c
@@ -230,6 +230,18 @@ aio_ctx_finalize(GSource     *source)
 {
     AioContext *ctx = (AioContext *) source;
 
+    qemu_mutex_lock(&ctx->bh_lock);
+    while (ctx->first_bh) {
+        QEMUBH *next = ctx->first_bh->next;
+
+        /* qemu_bh_delete() must have been called on BHs in this AioContext */
+        assert(ctx->first_bh->deleted);
+
+        g_free(ctx->first_bh);
+        ctx->first_bh = next;
+    }
+    qemu_mutex_unlock(&ctx->bh_lock);
+
     thread_pool_free(ctx->thread_pool);
     aio_set_event_notifier(ctx, &ctx->notifier, NULL);
     event_notifier_cleanup(&ctx->notifier);
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]