From nobody Fri May 16 10:12:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496496482046411.9909941456025; Sat, 3 Jun 2017 06:28:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FB52142A7B; Sat, 3 Jun 2017 13:27:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71A3E19E89; Sat, 3 Jun 2017 13:27:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 23CCF180BAF4; Sat, 3 Jun 2017 13:27:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DRiGu008506 for ; Sat, 3 Jun 2017 09:27:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 629AC78371; Sat, 3 Jun 2017 13:27:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2188917F25 for ; Sat, 3 Jun 2017 13:27:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FB52142A7B Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9FB52142A7B From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:27:37 -0400 Message-Id: <20170603132737.27650-9-jferlan@redhat.com> In-Reply-To: <20170603132737.27650-1-jferlan@redhat.com> References: <20170603132737.27650-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] secret: Handle object list removal and deletion properly X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 03 Jun 2017 13:28:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than rely on virSecretObjEndAPI to make the final virObjectUnref after the call virSecretObjListRemove, be more explicit by calling virObjectUnref and setting @obj to NULL for secretUndefine and in the error path of secretDefineXML. This also fixes a leak during virSecretLoad if the virSecretLoadValue fails the code jumps to cleanup without setting @ret =3D obj, thus calling virSecretObjListRemove which only accounts for the object reference related to adding the object to the list during virSecretObjListAdd, but does not account for the reference to the object itself as the return of @ret would be NULL so the caller wouldn't call virSecretObjEndAPI on the object recently added thus reducing the refcnt to zero. Thus cleaning up the virSecretLoadValue error path to make it clearer what needs to be done on failure. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 14 ++++++-------- src/secret/secret_driver.c | 9 +++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index ca13cf8..26646dd 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -918,7 +918,6 @@ virSecretLoad(virSecretObjListPtr secrets, { virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; - virSecretObjPtr ret =3D NULL; =20 if (!(def =3D virSecretDefParseFile(path))) goto cleanup; @@ -930,16 +929,15 @@ virSecretLoad(virSecretObjListPtr secrets, goto cleanup; def =3D NULL; =20 - if (virSecretLoadValue(obj) < 0) - goto cleanup; - - ret =3D obj; - obj =3D NULL; + if (virSecretLoadValue(obj) < 0) { + virSecretObjListRemove(secrets, obj); + virObjectUnref(obj); + obj =3D NULL; + } =20 cleanup: - virSecretObjListRemove(secrets, obj); virSecretDefFree(def); - return ret; + return obj; } =20 =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 32cd8bb..14483fd 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -268,10 +268,13 @@ secretDefineXML(virConnectPtr conn, * the backup. The current def will be handled below. * Otherwise, this is a new secret, thus remove it. */ - if (backup) + if (backup) { virSecretObjSetDef(obj, backup); - else + } else { virSecretObjListRemove(driver->secrets, obj); + virObjectUnref(obj); + obj =3D NULL; + } =20 cleanup: virSecretDefFree(def); @@ -411,6 +414,8 @@ secretUndefine(virSecretPtr secret) virSecretObjDeleteData(obj); =20 virSecretObjListRemove(driver->secrets, obj); + virObjectUnref(obj); + obj =3D NULL; =20 ret =3D 0; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list