From nobody Fri May 3 10:56:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522166964948387.9856663272018; Tue, 27 Mar 2018 09:09:24 -0700 (PDT) Received: from localhost ([::1]:35161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0r9v-0005jO-9r for importer@patchew.org; Tue, 27 Mar 2018 12:09:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0r8f-00050r-Us for qemu-devel@nongnu.org; Tue, 27 Mar 2018 12:07:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0r8f-0004k3-0b for qemu-devel@nongnu.org; Tue, 27 Mar 2018 12:07:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41940 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0r8b-0004ie-04; Tue, 27 Mar 2018 12:07:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04F3881A8B92; Tue, 27 Mar 2018 16:07:49 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74BF42026E03; Tue, 27 Mar 2018 16:07:44 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 27 Mar 2018 18:07:36 +0200 Message-Id: <20180327160736.24309-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 27 Mar 2018 16:07:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 27 Mar 2018 16:07:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] blockjob: leak fix, remove from txn when failing early X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jcody@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This fixes leaks found by ASAN such as: GTESTER tests/test-blockjob =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D31442=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f88483cba38 in __interceptor_calloc (/lib64/libasan.so.4+0xdea38) #1 0x7f8845e1bd77 in g_malloc0 ../glib/gmem.c:129 #2 0x7f8845e1c04b in g_malloc0_n ../glib/gmem.c:360 #3 0x5584d2732498 in block_job_txn_new /home/elmarco/src/qemu/blockjob.= c:172 #4 0x5584d2739b28 in block_job_create /home/elmarco/src/qemu/blockjob.c= :973 #5 0x5584d270ae31 in mk_job /home/elmarco/src/qemu/tests/test-blockjob.= c:34 #6 0x5584d270b1c1 in do_test_id /home/elmarco/src/qemu/tests/test-block= job.c:57 #7 0x5584d270b65c in test_job_ids /home/elmarco/src/qemu/tests/test-blo= ckjob.c:118 #8 0x7f8845e40b69 in test_case_run ../glib/gtestutils.c:2255 #9 0x7f8845e40f29 in g_test_run_suite_internal ../glib/gtestutils.c:2339 #10 0x7f8845e40fd2 in g_test_run_suite_internal ../glib/gtestutils.c:23= 51 #11 0x7f8845e411e9 in g_test_run_suite ../glib/gtestutils.c:2426 #12 0x7f8845e3fe72 in g_test_run ../glib/gtestutils.c:1692 #13 0x5584d270d6e2 in main /home/elmarco/src/qemu/tests/test-blockjob.c= :377 #14 0x7f8843641f29 in __libc_start_main (/lib64/libc.so.6+0x20f29) Add an assert to make sure that the job doesn't have associated txn before = free(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: John Snow --- blockjob.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blockjob.c b/blockjob.c index 11c9ce124d..bb75386515 100644 --- a/blockjob.c +++ b/blockjob.c @@ -228,6 +228,7 @@ void block_job_unref(BlockJob *job) { if (--job->refcnt =3D=3D 0) { assert(job->status =3D=3D BLOCK_JOB_STATUS_NULL); + assert(!job->txn); BlockDriverState *bs =3D blk_bs(job->blk); QLIST_REMOVE(job, job_list); bs->job =3D NULL; @@ -479,6 +480,7 @@ static int block_job_finalize_single(BlockJob *job) =20 QLIST_REMOVE(job, txn_list); block_job_txn_unref(job->txn); + job->txn =3D NULL; block_job_conclude(job); return 0; } @@ -994,6 +996,9 @@ void block_job_pause_all(void) void block_job_early_fail(BlockJob *job) { assert(job->status =3D=3D BLOCK_JOB_STATUS_CREATED); + QLIST_REMOVE(job, txn_list); + block_job_txn_unref(job->txn); + job->txn =3D NULL; block_job_decommission(job); } =20 --=20 2.17.0.rc1.1.g4c4f2b46a3