From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: cornelia.huck@de.ibm.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH for-2.4 v3 2/3] AioContext: avoid leaking BHs on cleanup
Date: Tue, 28 Jul 2015 18:34:08 +0200 [thread overview]
Message-ID: <1438101249-25166-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1438101249-25166-1-git-send-email-pbonzini@redhat.com>
From: Stefan Hajnoczi <stefanha@redhat.com>
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>
Message-Id: <1438014819-18125-2-git-send-email-stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
v1->v3: place loop after thread_pool_free
async.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
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);
--
2.4.3
next prev parent reply other threads:[~2015-07-28 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-28 16:34 [Qemu-devel] [PATCH for-2.4 v3 0/3] AioContext: fix deadlock after aio_context_acquire() race Paolo Bonzini
2015-07-28 16:34 ` [Qemu-devel] [PATCH for-2.4 v3 1/3] virtio-blk-dataplane: delete bottom half before the AioContext is freed Paolo Bonzini
2015-07-28 16:34 ` Paolo Bonzini [this message]
2015-07-28 16:34 ` [Qemu-devel] [PATCH for-2.4 v3 3/3] AioContext: force event loop iteration using BH Paolo Bonzini
2015-07-29 9:02 ` [Qemu-devel] [PATCH for-2.4 v3 0/3] AioContext: fix deadlock after aio_context_acquire() race Stefan Hajnoczi
2015-07-29 9:08 ` Cornelia Huck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438101249-25166-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=cornelia.huck@de.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).