From nobody Sun Feb 8 23:36:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1669990693; cv=none; d=zohomail.com; s=zohoarc; b=JFvvtpEsvuFI9IfhPgBJ254e5MFTmHlEd/WXMSDUXJoQxB+NeXRP4X1qXB9T0U4fbPSHKueWTd4m5xQ0XR29rhYyM69lOOdhodg0rIviUsbvQtzHAyFeZds0FnB7r33AZBz+O3mqTAjA4wfkknsL/gvDvDQifDPm4+14b5LLu6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669990693; 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=584QpiRxRz8fhlkbDH0r5h+RTFBS56uRtdex7PU2fNQ=; b=dbrV4TwW/DwYU8NQsX3wcBMKIsPzx0j/jMmrmry+NEEi6cLdGWqfqTCxiILFAXTCissZ7soLKG5fiALM9Q2Anr7Peq/iWwQwWdLE0FxFeFpOV40c3fKN2pJo6mo0T39E53WsQHQhr6++XjSlgvXBsGMBQXJOQKQv8UZrqN1MSCs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1669990693213201.86610679561534; Fri, 2 Dec 2022 06:18:13 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-sTb2XJyiMua2MHJ549fHIg-1; Fri, 02 Dec 2022 09:17:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1165985A588; Fri, 2 Dec 2022 14:17:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0CE92166B2A; Fri, 2 Dec 2022 14:17:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E6A43194658F; Fri, 2 Dec 2022 14:17:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9E24F19465B8 for ; Fri, 2 Dec 2022 14:17:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 744D540E9785; Fri, 2 Dec 2022 14:17:06 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFBF740E9789 for ; Fri, 2 Dec 2022 14:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669990692; 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=584QpiRxRz8fhlkbDH0r5h+RTFBS56uRtdex7PU2fNQ=; b=OiwIYPNWAXgfCF0JKniS2kMHUT78ToI9VoqxJnClBra0gW646VI2AXIsP6cihDjVK60pmB sW2/3G2CJbRIw4ZvgnfuN/0AvACY69WsQ+rk2HMmJMH/3zgQd5cE8sGZORQwTLXO6uDCBk 0k0MrzxK7B4fzPj6MdxwtWSQMUg3DfY= X-MC-Unique: sTb2XJyiMua2MHJ549fHIg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/13] virsh: Refactor cleanup in 'cmdVolClone' Date: Fri, 2 Dec 2022 15:16:49 +0100 Message-Id: <1baa339f38efd0283eb9ae5c8f2691502b2dd0bd.1669990545.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1669990694869100003 Content-Type: text/plain; charset="utf-8" Automatically free 'newxml' and remove the 'cleanup' label and 'ret' variable. Signed-off-by: Peter Krempa --- tools/virsh-volume.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4f23481180..b7a1ddb9e5 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -570,12 +570,11 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) newvol =3D NULL; const char *name =3D NULL; g_autofree char *origxml =3D NULL; - xmlChar *newxml =3D NULL; - bool ret =3D false; + g_autofree xmlChar *newxml =3D NULL; unsigned int flags =3D 0; if (!(origvol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |=3D VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; @@ -586,38 +585,30 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) origpool =3D virStoragePoolLookupByVolume(origvol); if (!origpool) { vshError(ctl, "%s", _("failed to get parent pool")); - goto cleanup; + return false; } if (vshCommandOptStringReq(ctl, cmd, "newname", &name) < 0) - goto cleanup; + return false; - origxml =3D virStorageVolGetXMLDesc(origvol, 0); - if (!origxml) - goto cleanup; + if (!(origxml =3D virStorageVolGetXMLDesc(origvol, 0))) + return false; - newxml =3D virshMakeCloneXML(origxml, name); - if (!newxml) { + if (!(newxml =3D virshMakeCloneXML(origxml, name))) { vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; + return false; } - newvol =3D virStorageVolCreateXMLFrom(origpool, (char *) newxml, origv= ol, flags); - - if (newvol !=3D NULL) { - vshPrintExtra(ctl, _("Vol %s cloned from %s\n"), - virStorageVolGetName(newvol), virStorageVolGetName(o= rigvol)); - } else { + if (!(newvol =3D virStorageVolCreateXMLFrom(origpool, (char *) newxml, + origvol, flags))) { vshError(ctl, _("Failed to clone vol from %s"), virStorageVolGetName(origvol)); - goto cleanup; + return false; } - ret =3D true; - - cleanup: - xmlFree(newxml); - return ret; + vshPrintExtra(ctl, _("Vol %s cloned from %s\n"), + virStorageVolGetName(newvol), virStorageVolGetName(origv= ol)); + return true; } /* --=20 2.38.1