From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKRkl-0005Do-Cp for qemu-devel@nongnu.org; Wed, 29 Jul 2015 09:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKRkk-0004FU-37 for qemu-devel@nongnu.org; Wed, 29 Jul 2015 09:50:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKRkj-0004FB-Ta for qemu-devel@nongnu.org; Wed, 29 Jul 2015 09:50:37 -0400 From: Stefan Hajnoczi Date: Wed, 29 Jul 2015 14:50:30 +0100 Message-Id: <1438177831-28195-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1438177831-28195-1-git-send-email-stefanha@redhat.com> References: <1438177831-28195-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL for-2.4 2/3] AioContext: avoid leaking BHs on cleanup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Paolo Bonzini 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 Signed-off-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini 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 Signed-off-by: Stefan Hajnoczi --- 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