From nobody Mon Feb 9 20:10:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579882137; cv=none; d=zohomail.com; s=zohoarc; b=iPmkjomEVPyyS9zBpiyO/dFYBGe0N3gEWcfDf4Gt459IRpwo5so2ee9B3EaqEuCDn3jJOlx+9+qHRmBbKpzIO/HDoqmf+hgtuH10MrOdUav4AsVZT/vNr7JzL1rH4kLzgeArQdXQWmmDoEeAAeEk288jO/uLOzYzV5BfhNRF2Zs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579882137; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rUIbHOuYTn2sHb+f6FZNAXGrDsCtgLaib4JDNEqxBrg=; b=TrectUKATS5R0F7acht7/yfiwBqnFbeG6z+sCmbLagRUYPeKIbvgrUBLEbV39zuwb+Eu7508GEF5Fu0LogHdgSXsf+XV6pgC/SwOzCjFDyow266TwHTsvfTmnZrtXyGPhChoyYCrk5HXHdMDH2rQBn6UNbBNyucZbZRrbQTd5ls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1579882137674305.78468128574957; Fri, 24 Jan 2020 08:08:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-Hnm4XkXqPrGQcRTkKztjSA-1; Fri, 24 Jan 2020 11:08:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75CA48D8F12; Fri, 24 Jan 2020 16:08:48 +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 479FB5C241; Fri, 24 Jan 2020 16:08:48 +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 E95B285964; Fri, 24 Jan 2020 16:08:47 +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 00OG8k4B011890 for ; Fri, 24 Jan 2020 11:08:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E47C5C241; Fri, 24 Jan 2020 16:08:46 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BB575C1B0 for ; Fri, 24 Jan 2020 16:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579882136; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rUIbHOuYTn2sHb+f6FZNAXGrDsCtgLaib4JDNEqxBrg=; b=MrUbzTNj82wJcc7OtfPVSzeNR5f564PUGkfQdsH2E2UTRMGfM9Qq/Tpk9phSZGZlcSAlrv BIyX9yf+GCs8GK++AqmBs1nTj4oBbk/eCNjVBi5X9p/SBswYmGH6Jgz2EyYP0jqs183sBz tISkaQOmBS8GpzwKw6SC7V1J8rSF5Vw= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 1/9] virsh: Work around virSecretFree quirks Date: Fri, 24 Jan 2020 17:08:33 +0100 Message-Id: <3d998daf712dcc16fb48696b106e8b61e0e14ce0.1579881978.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: Hnm4XkXqPrGQcRTkKztjSA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Similarly to other libvirt object freeing APIs the function resets the libvirt error when called and doesn't take NULL gracefully. Install the workaround and g_autoptr handlers similarly to the 'virshDomain' type. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-secret.c | 3 ++- tools/virsh-secret.c | 22 ++++++++++------------ tools/virsh-util.c | 11 +++++++++++ tools/virsh-util.h | 5 +++++ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index e5623606dd..14122476de 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1118,7 +1118,7 @@ sc_gettext_init: $(_sc_search_regexp) sc_prohibit_obj_free_apis_in_virsh: - @prohibit=3D'\bvir(Domain|DomainSnapshot)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Secret)Free\b' \ in_vc_files=3D'virsh.*\.[ch]$$' \ exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ halt=3D'avoid using virDomain(Snapshot)Free in virsh, use virsh-prefixed = wrappers instead' \ diff --git a/tools/virsh-completer-secret.c b/tools/virsh-completer-secret.c index a90fdb399f..505b19db84 100644 --- a/tools/virsh-completer-secret.c +++ b/tools/virsh-completer-secret.c @@ -23,6 +23,7 @@ #include "virsh-completer-secret.h" #include "viralloc.h" #include "virsh-secret.h" +#include "virsh-util.h" #include "virsh.h" #include "virstring.h" @@ -61,7 +62,7 @@ virshSecretUUIDCompleter(vshControl *ctl, cleanup: for (i =3D 0; i < nsecrets; i++) - virSecretFree(secrets[i]); + virshSecretFree(secrets[i]); VIR_FREE(secrets); return ret; } diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 01c62b9ce8..7123b10860 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -20,6 +20,7 @@ #include #include "virsh-secret.h" +#include "virsh-util.h" #include "internal.h" #include "virbuffer.h" @@ -106,8 +107,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - if (res) - virSecretFree(res); + virshSecretFree(res); return ret; } @@ -153,7 +153,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virSecretFree(secret); + virshSecretFree(secret); return ret; } @@ -215,7 +215,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virSecretFree(secret); + virshSecretFree(secret); return ret; } @@ -266,7 +266,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_DISPOSE_N(value, value_size); - virSecretFree(secret); + virshSecretFree(secret); return ret; } @@ -312,7 +312,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - virSecretFree(secret); + virshSecretFree(secret); return ret; } @@ -348,10 +348,9 @@ virshSecretListFree(virshSecretListPtr list) size_t i; if (list && list->secrets) { - for (i =3D 0; i < list->nsecrets; i++) { - if (list->secrets[i]) - virSecretFree(list->secrets[i]); - } + for (i =3D 0; i < list->nsecrets; i++) + virshSecretFree(list->secrets[i]); + VIR_FREE(list->secrets); } VIR_FREE(list); @@ -763,8 +762,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >=3D 0 && virConnectSecretEventDeregisterAny(priv->conn, eventId) < 0) ret =3D false; - if (secret) - virSecretFree(secret); + virshSecretFree(secret); return ret; } diff --git a/tools/virsh-util.c b/tools/virsh-util.c index f436fbb486..932d6d0849 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -250,6 +250,17 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) } +void +virshSecretFree(virSecretPtr secret) +{ + if (!secret) + return; + + vshSaveLibvirtHelperError(); + virSecretFree(secret); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + int virshDomainGetXMLFromDom(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 2b0447268e..72653d9735 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -45,6 +45,11 @@ void virshDomainFree(virDomainPtr dom); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomain, virshDomainFree); +typedef virSecret virshSecret; +void +virshSecretFree(virSecretPtr secret); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree); + void virshDomainCheckpointFree(virDomainCheckpointPtr chk); --=20 2.24.1