summaryrefslogtreecommitdiffstats
path: root/async.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2015-07-28 18:34:08 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2015-07-29 10:02:06 +0100
commita076972a4d36381d610a854f0c336507650a1d34 (patch)
tree50e4917af7aea8f00851af878fc59ccf109f2ebb /async.c
parentfed105e2756dde98efa5e80baca02ae516dd1e51 (diff)
downloadhqemu-a076972a4d36381d610a854f0c336507650a1d34.zip
hqemu-a076972a4d36381d610a854f0c336507650a1d34.tar.gz
AioContext: avoid leaking BHs on cleanup
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 <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1438101249-25166-3-git-send-email-pbonzini@redhat.com Message-Id: <1438014819-18125-2-git-send-email-stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'async.c')
-rw-r--r--async.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/async.c b/async.c
index 9a98a74..8d23681 100644
--- a/async.c
+++ b/async.c
@@ -231,6 +231,19 @@ aio_ctx_finalize(GSource *source)
AioContext *ctx = (AioContext *) source;
thread_pool_free(ctx->thread_pool);
+
+ 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);
+
aio_set_event_notifier(ctx, &ctx->notifier, NULL);
event_notifier_cleanup(&ctx->notifier);
rfifolock_destroy(&ctx->lock);
OpenPOWER on IntegriCloud