From nobody Sat Apr 27 09:48:04 2024 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.zohomail.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 15000411083281023.6551136446033; Fri, 14 Jul 2017 07:05:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52FEBC0567B3; Fri, 14 Jul 2017 14:05:02 +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 028B177644; Fri, 14 Jul 2017 14:05:02 +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 9604E1833033; Fri, 14 Jul 2017 14:05:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6EE4mHb026860 for ; Fri, 14 Jul 2017 10:04:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5AA7065EBE; Fri, 14 Jul 2017 14:04:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D70467CC4 for ; Fri, 14 Jul 2017 14:04:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 52FEBC0567B3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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 52FEBC0567B3 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 14 Jul 2017 10:04:39 -0400 Message-Id: <20170714140442.21315-2-jferlan@redhat.com> In-Reply-To: <20170714140442.21315-1-jferlan@redhat.com> References: <20170714140442.21315-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/4] secret: Clean up virSecretObjListAdd processing 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 14 Jul 2017 14:05:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make use of an error: label to handle the failure and need to call virSecretObjEndAPI for the object to set it to NULL for return. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index e3bcbe5..bedcdbd 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -333,7 +333,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, { virSecretObjPtr obj; virSecretDefPtr objdef; - virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; =20 @@ -354,13 +353,13 @@ virSecretObjListAdd(virSecretObjListPtr secrets, _("a secret with UUID %s is already defined for= " "use with %s"), uuidstr, objdef->usage_id); - goto cleanup; + goto error; } =20 if (objdef->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); - goto cleanup; + goto error; } =20 if (oldDef) @@ -369,8 +368,9 @@ virSecretObjListAdd(virSecretObjListPtr secrets, virSecretDefFree(objdef); obj->def =3D newdef; } else { + /* No existing secret with same UUID, - * try look for matching usage instead */ + * try to look for matching usage instead */ if ((obj =3D virSecretObjListFindByUsageLocked(secrets, newdef->usage_type, newdef->usage_id))) { @@ -381,7 +381,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, _("a secret with UUID %s already defined for " "use with %s"), uuidstr, newdef->usage_id); - goto cleanup; + goto error; } =20 /* Generate the possible configFile and base64File strings @@ -395,7 +395,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto cleanup; =20 if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) - goto cleanup; + goto error; =20 obj->def =3D newdef; VIR_STEAL_PTR(obj->configFile, configFile); @@ -403,15 +403,15 @@ virSecretObjListAdd(virSecretObjListPtr secrets, virObjectRef(obj); } =20 - ret =3D obj; - obj =3D NULL; - cleanup: - virSecretObjEndAPI(&obj); VIR_FREE(configFile); VIR_FREE(base64File); virObjectUnlock(secrets); - return ret; + return obj; + + error: + virSecretObjEndAPI(&obj); + goto cleanup; } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:48:04 2024 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.zohomail.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 1500041103968939.6416980970719; Fri, 14 Jul 2017 07:05:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5A8B7F3E1; Fri, 14 Jul 2017 14:04:52 +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 2D028703A7; Fri, 14 Jul 2017 14:04:52 +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 A8C131803B26; Fri, 14 Jul 2017 14:04:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6EE4mpg026865 for ; Fri, 14 Jul 2017 10:04:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C1A2165EBE; Fri, 14 Jul 2017 14:04:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 877AE67CC8 for ; Fri, 14 Jul 2017 14:04:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5A8B7F3E1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 C5A8B7F3E1 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 14 Jul 2017 10:04:40 -0400 Message-Id: <20170714140442.21315-3-jferlan@redhat.com> In-Reply-To: <20170714140442.21315-1-jferlan@redhat.com> References: <20170714140442.21315-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/4] secret: Remove need for local configFile and base64File in ObjectAdd 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 14:04:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than assign to a local variable, let's just assign directly to the object using the error path for cleanup. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index bedcdbd..dd36ce6 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -334,7 +334,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets, virSecretObjPtr obj; virSecretDefPtr objdef; char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile =3D NULL, *base64File =3D NULL; =20 virObjectLock(secrets); =20 @@ -384,28 +383,24 @@ virSecretObjListAdd(virSecretObjListPtr secrets, goto error; } =20 + if (!(obj =3D virSecretObjNew())) + goto cleanup; + /* Generate the possible configFile and base64File strings * using the configDir, uuidstr, and appropriate suffix */ - if (!(configFile =3D virFileBuildPath(configDir, uuidstr, ".xml"))= || - !(base64File =3D virFileBuildPath(configDir, uuidstr, ".base64= "))) - goto cleanup; - - if (!(obj =3D virSecretObjNew())) - goto cleanup; + if (!(obj->configFile =3D virFileBuildPath(configDir, uuidstr, ".x= ml")) || + !(obj->base64File =3D virFileBuildPath(configDir, uuidstr, ".b= ase64"))) + goto error; =20 if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) goto error; =20 obj->def =3D newdef; - VIR_STEAL_PTR(obj->configFile, configFile); - VIR_STEAL_PTR(obj->base64File, base64File); virObjectRef(obj); } =20 cleanup: - VIR_FREE(configFile); - VIR_FREE(base64File); virObjectUnlock(secrets); return obj; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:48:04 2024 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.zohomail.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 150004109962484.7793147583169; Fri, 14 Jul 2017 07:04:59 -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 5CABC65983; Fri, 14 Jul 2017 14:04:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2792F7DE1E; Fri, 14 Jul 2017 14:04:55 +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 81CBC4E987; Fri, 14 Jul 2017 14:04:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6EE4riY026885 for ; Fri, 14 Jul 2017 10:04:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C05467CE7; Fri, 14 Jul 2017 14:04:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7AC267CF2 for ; Fri, 14 Jul 2017 14:04:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5CABC65983 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 5CABC65983 From: John Ferlan To: libvir-list@redhat.com Date: Fri, 14 Jul 2017 10:04:41 -0400 Message-Id: <20170714140442.21315-4-jferlan@redhat.com> In-Reply-To: <20170714140442.21315-1-jferlan@redhat.com> References: <20170714140442.21315-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/4] secret: Properly handle @def after virSecretObjAdd in driver 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.38]); Fri, 14 Jul 2017 14:04:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the virSecretObjListAdd technically consumes @def on success, the secretDefineXML should set @def =3D NULL immediately and process the remaining calls using a new @objdef variable. We can use use VIR_STEAL_PTR since we know the Add function just stores @def in obj->def. This fixes a possible double free of @def if the code jumps to restore_backup: and calls virSecretObjListRemove without setting def =3D NULL. In this case, the subsequent call to DefFree would succeed and free @def; however, the call to EndAPI would also call DefFree because the Unref done would be the last one for the @obj meaning the obj->def would be used to call DefFree, but it's already been free'd because @def wasn't managed right within this error path. Signed-off-by: John Ferlan --- src/secret/secret_driver.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 30124b4..77351d8 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -210,6 +210,7 @@ secretDefineXML(virConnectPtr conn, { virSecretPtr ret =3D NULL; virSecretObjPtr obj =3D NULL; + virSecretDefPtr objdef; virSecretDefPtr backup =3D NULL; virSecretDefPtr def; virObjectEventPtr event =3D NULL; @@ -225,8 +226,9 @@ secretDefineXML(virConnectPtr conn, if (!(obj =3D virSecretObjListAdd(driver->secrets, def, driver->configDir, &backup))) goto cleanup; + VIR_STEAL_PTR(objdef, def); =20 - if (!def->isephemeral) { + if (!objdef->isephemeral) { if (backup && backup->isephemeral) { if (virSecretObjSaveData(obj) < 0) goto restore_backup; @@ -248,22 +250,21 @@ secretDefineXML(virConnectPtr conn, /* Saved successfully - drop old values */ virSecretDefFree(backup); =20 - event =3D virSecretEventLifecycleNew(def->uuid, - def->usage_type, - def->usage_id, + event =3D virSecretEventLifecycleNew(objdef->uuid, + objdef->usage_type, + objdef->usage_id, VIR_SECRET_EVENT_DEFINED, 0); =20 ret =3D virGetSecret(conn, - def->uuid, - def->usage_type, - def->usage_id); - def =3D NULL; + objdef->uuid, + objdef->usage_type, + objdef->usage_id); goto cleanup; =20 restore_backup: /* If we have a backup, then secret was defined before, so just restore - * the backup. The current def will be handled below. + * the backup. The current def will be Free'd below. * Otherwise, this is a new secret, thus remove it. */ if (backup) --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 09:48:04 2024 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.zohomail.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 1500041116988794.0275511004951; Fri, 14 Jul 2017 07:05:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF5F37F3ED; Fri, 14 Jul 2017 14:05:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD74C6062C; Fri, 14 Jul 2017 14:05:05 +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 6FD214E98C; Fri, 14 Jul 2017 14:05:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6EE4rKO026890 for ; Fri, 14 Jul 2017 10:04:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91D3067CFE; Fri, 14 Jul 2017 14:04:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59A9467CF2 for ; Fri, 14 Jul 2017 14:04:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AF5F37F3ED Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 AF5F37F3ED From: John Ferlan To: libvir-list@redhat.com Date: Fri, 14 Jul 2017 10:04:42 -0400 Message-Id: <20170714140442.21315-5-jferlan@redhat.com> In-Reply-To: <20170714140442.21315-1-jferlan@redhat.com> References: <20170714140442.21315-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/4] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 14 Jul 2017 14:05:08 +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 to virSecretObjListRemove, be more explicit by calling virObjectUnref and setting @obj to NULL for secretUndefine and in the error path of secretDefineXML. Calling EndAPI will end up calling Unlock on an already unlocked object which has indeteriminate results (usually an ignored error). The virSecretObjEndAPI will both Unref and Unlock the object; however, the virSecretObjListRemove would have already Unlock'd the object so calling Unlock again is incorrect. Once the virSecretObjListRemove is called all that's left is to Unref our interest since that's the corrollary to the virSecretObjListAdd which returned our ref interest plus references for each hash table in which the object resides. In math terms, after an Add there's 2 refs on the object (1 for the object and 1 for the list). After calling Remove there's just 1 ref on the object. For the Add callers, calling EndAPI removes the ref for the object and unlocks it, but since it's in a list the other 1 remains. 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 dd36ce6..0e7675e 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -914,7 +914,6 @@ virSecretLoad(virSecretObjListPtr secrets, { virSecretDefPtr def =3D NULL; virSecretObjPtr obj =3D NULL; - virSecretObjPtr ret =3D NULL; =20 if (!(def =3D virSecretDefParseFile(path))) goto cleanup; @@ -926,16 +925,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 77351d8..19ba6fd 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -267,10 +267,13 @@ secretDefineXML(virConnectPtr conn, * the backup. The current def will be Free'd 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); @@ -410,6 +413,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