From nobody Tue Feb 10 05:44:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1632719299; cv=none; d=zohomail.com; s=zohoarc; b=ROpsQHRRhXWLL2k12wXzQnPtDPDCPy6jPzbsA/eofwTd5+IPUFFdIxIXm9gV+SO1CukedoovcSUvd/WxXDlaD4tikRx1oOre0j+/93FCrdIt96qQAH7WPS8cUS1YrpbonxUSoxKdtprXWLwzttNFBUuOFKrizppulGsaXUsqxYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719299; 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=J3Lf2dSD+pectOd8UmJMfcGWF/loMim3e+ChQQhvFBs=; b=X2Kyr7KI/AfH5j4D99HlHyOIvqcrKzSkD3HEjjOlb2wfFno5ip0v2sMcGD+2VCm5uOvo22gk4K/Xq9zA4zObfieeXJzMBvsaF5tno7cAyVf4KDUR0aoIF8eFItMMxV+6M4qwVYnmHeiqVp1HJ3YpXNZj/+a8RJIG0cjgrGyQqEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632719299020636.6905479010439; Sun, 26 Sep 2021 22:08:19 -0700 (PDT) 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-496-Zj6QCacFNdWAJuI3cz2vIg-1; Mon, 27 Sep 2021 01:08:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6C5E36300; Mon, 27 Sep 2021 05:08:09 +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 8508A17B5B; Mon, 27 Sep 2021 05:08:09 +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 210E84EA39; Mon, 27 Sep 2021 05:08:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18R58614004254 for ; Mon, 27 Sep 2021 01:08:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DB6D189C4; Mon, 27 Sep 2021 05:08:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E538B652A1 for ; Mon, 27 Sep 2021 05:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719298; 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=J3Lf2dSD+pectOd8UmJMfcGWF/loMim3e+ChQQhvFBs=; b=Nvj3j/H+lq7wLHwpA22Pritu9+dZqELM12eoQszXZPruOV2aO7xzpM5Prrk2160MMn2TEM AoKjHFZeTwismhUnHp9qsWP7U5Lac3XrEkjNIMk2Q6K5sRyjzGCz4wOIgJXlbVoxLlzecU Hw+vNyF0K/s5xv41++ckLyFkrKUHdpk= X-MC-Unique: Zj6QCacFNdWAJuI3cz2vIg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 8/8] virsh: Add wrapper for virStreamFree Date: Mon, 27 Sep 2021 07:07:50 +0200 Message-Id: <1549ea00db7252709bdcec1425ca24739fe8f049.1632718996.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632719300827100003 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tools/virsh-console.c | 8 ++++---- tools/virsh-domain.c | 4 +--- tools/virsh-util.c | 12 ++++++++++++ tools/virsh-util.h | 5 +++++ tools/virsh-volume.c | 8 ++------ 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 5daf5afcd0..cb12b64532 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -868,7 +868,7 @@ sc_gettext_init: $(_sc_search_regexp) =20 sc_prohibit_obj_free_apis_in_virsh: - @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWF= ilter|Secret|StoragePool|StorageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWF= ilter|Secret|StoragePool|StorageVol|Stream)Free\b' \ in_vc_files=3D'virsh.*\.[ch]$$' \ exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ halt=3D'avoid using public virXXXFree in virsh, use virsh-prefixed wrappe= rs instead' \ diff --git a/tools/virsh-console.c b/tools/virsh-console.c index 449619c95f..67ee608706 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -33,6 +33,7 @@ # include "internal.h" # include "virsh.h" # include "virsh-console.h" +# include "virsh-util.h" # include "virlog.h" # include "virfile.h" # include "viralloc.h" @@ -117,8 +118,8 @@ virConsoleShutdown(virConsole *con, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot terminate console stream")); } - virStreamFree(con->st); - con->st =3D NULL; + + g_clear_pointer(&con->st, virshStreamFree); } VIR_FREE(con->streamToTerminal.data); VIR_FREE(con->terminalToStream.data); @@ -140,8 +141,7 @@ virConsoleDispose(void *obj) { virConsole *con =3D obj; =20 - if (con->st) - virStreamFree(con->st); + virshStreamFree(con->st); =20 virCondDestroy(&con->cond); virResetError(&con->error); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b1943b3875..0d4f7cc407 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5540,7 +5540,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) const char *name =3D NULL; char *file =3D NULL; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; unsigned int screen =3D 0; unsigned int flags =3D 0; /* currently unused */ bool ret =3D false; @@ -5610,8 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - if (st) - virStreamFree(st); VIR_FORCE_CLOSE(fd); VIR_FREE(mime); return ret; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index fc2839d8fc..8fb617fa3c 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -362,6 +362,18 @@ virshStorageVolFree(virStorageVolPtr vol) } =20 =20 + +void +virshStreamFree(virStreamPtr stream) +{ + if (!stream) + return; + + vshSaveLibvirtHelperError(); + virStreamFree(stream); /* 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 065055ddb1..838935d5e8 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -89,6 +89,11 @@ void virshStorageVolFree(virStorageVolPtr vol); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree); =20 +typedef virStream virshStream; +void +virshStreamFree(virStreamPtr stream); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStream, virshStreamFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b896ebbbf9..70b6eac687 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -656,7 +656,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; const char *name =3D NULL; unsigned long long offset =3D 0, length =3D 0; virshControl *priv =3D ctl->privData; @@ -731,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (st) - virStreamFree(st); VIR_FORCE_CLOSE(fd); return ret; } @@ -776,7 +774,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; const char *name =3D NULL; unsigned long long offset =3D 0, length =3D 0; bool created =3D false; @@ -851,8 +849,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) VIR_FORCE_CLOSE(fd); if (!ret && created) unlink(file); - if (st) - virStreamFree(st); return ret; } =20 --=20 2.32.0