From nobody Mon Feb 9 15:26:50 2026 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714205002321.3472413015361; Wed, 8 Aug 2018 00:43:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A702080F7A; Wed, 8 Aug 2018 07:43:22 +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 69C023001A5A; Wed, 8 Aug 2018 07:43:22 +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 1FF5918037ED; Wed, 8 Aug 2018 07:43:22 +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 w787hCDg005462 for ; Wed, 8 Aug 2018 03:43:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id A2F4938194; Wed, 8 Aug 2018 07:43:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BA8D38195 for ; Wed, 8 Aug 2018 07:43:10 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D1B9308402D for ; Wed, 8 Aug 2018 07:43:09 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id y5-v6so699839pgv.1 for ; Wed, 08 Aug 2018 00:43:09 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=8YTHdBQLqE2bhawyT8ndL8eB8737FB6vsY3DZQ8LXd0=; b=SgZ59k8ucc0y/k2POoMxzKCX1PfcEP+EywNbgn2J3OTXMVSJ/DT37a7G8cs5cvF2s2 YTjrt7btIFT4K4TSvqtO/9z8QfHbHar87yzQQnKTIOHzEnTcQHXaxPcGUiHzYcO2sjug 7kBXSFrwGUwwbFAtn1AesiF6A5pysrVrMzqnAHe/hSYO1+gc7ooeAqaJfV9e5jmmMrVq gknBsiUxTGhkZPWP6I/5OVToCJDi0PD9LDINO8Xs4vv9y1FZ+YAr81HDZ2/3yLjGfnVt JM7l1i7FHuRTS9AyWHnWsxJ4U1lmf0/MFpIuSpMBKe3fRXI4+FHftOPq6Ho7g/UGOO8S VesA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8YTHdBQLqE2bhawyT8ndL8eB8737FB6vsY3DZQ8LXd0=; b=Iy26mhcYdSCjxjd1TzPIKOKhTySjqRXyvG35YFKVpkcpD0TWWnh08y4iqdBeeSfuX9 /kM1TL1rNHHj34N4xqOazuRe7ZScLttXdSqWkxyXlTIpeQ4pZGlypZbf7C7WKhBRMqex P+sS56RYBWbOYq8J6zCLx6EfJJmysTWPBjIXdMScSlwEmmlF901zN+IGR0DCmvn6FWjF ljCWrkZZTystW3gacn7w2j31rdGB6nQ0t7n0XdZGiUSTyefJ4VJYT+WA3zRMYkyITbDb 4+tTUWwvH8E+kj/P69QjA+N+h67SdCjM/ymf465KHZVk3Toyn3IUQK9BGuq3PrbBz2Ve ZSqg== X-Gm-Message-State: AOUpUlF92F5vyMm0DDlbU/eok/Ay6StNArqT58D5mc1jmId01XeIl98d udSb/v2Z/OG13wXp8n4xCtBRyeJf X-Google-Smtp-Source: AA+uWPwd2SnH1MAWcUdSiFilhTYGt6EPna34+mjMBjGR7IBvhcobOOuqj70JVLzoeKkewXvkn7TW9g== X-Received: by 2002:a62:6003:: with SMTP id u3-v6mr1732713pfb.114.1533714188390; Wed, 08 Aug 2018 00:43:08 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:28 +0530 Message-Id: <1533501842-24503-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:09 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/35] util: iscsi: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Aug 2018 07:43:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viriscsi.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index f00aeb5..0c2d8bb 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -88,8 +88,8 @@ virISCSIGetSession(const char *devpath, .session =3D NULL, .devpath =3D devpath, }; - char *error =3D NULL; int exitstatus =3D 0; + VIR_AUTOFREE(char *) error =3D NULL; =20 virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "session", NULL); @@ -109,7 +109,6 @@ virISCSIGetSession(const char *devpath, NULLSTR(error)); =20 cleanup: - VIR_FREE(error); virCommandFree(cmd); return cbdata.session; } @@ -125,12 +124,11 @@ virStorageBackendIQNFound(const char *initiatoriqn, char **ifacename) { int ret =3D IQN_ERROR; - char *outbuf =3D NULL; char *line =3D NULL; - char *iface =3D NULL; - char *iqn =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); + VIR_AUTOFREE(char *) outbuf =3D NULL; + VIR_AUTOFREE(char *) iqn =3D NULL; =20 *ifacename =3D NULL; =20 @@ -150,13 +148,13 @@ virStorageBackendIQNFound(const char *initiatoriqn, char *newline; char *next; size_t i; + VIR_AUTOFREE(char *) iface =3D NULL; =20 if (!(newline =3D strchr(line, '\n'))) break; =20 *newline =3D '\0'; =20 - VIR_FREE(iface); VIR_FREE(iqn); =20 /* Find the first space, copy everything up to that point into @@ -197,9 +195,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - VIR_FREE(iqn); - VIR_FREE(iface); - VIR_FREE(outbuf); virCommandFree(cmd); return ret; =20 @@ -216,8 +211,9 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, char **ifacename) { int ret =3D -1, exitstatus =3D -1; - char *temp_ifacename; virCommandPtr cmd =3D NULL; + VIR_AUTOFREE(char *) iface_name =3D NULL; + VIR_AUTOFREE(char *) temp_ifacename =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -263,23 +259,23 @@ virStorageBackendCreateIfaceIQN(const char *initiator= iqn, } =20 /* Check again to make sure the interface was created. */ - if (virStorageBackendIQNFound(initiatoriqn, ifacename) !=3D IQN_FOUND)= { + if (virStorageBackendIQNFound(initiatoriqn, &iface_name) !=3D IQN_FOUN= D) { VIR_DEBUG("Failed to find interface '%s' with IQN '%s' " "after attempting to create it", &temp_ifacename[0], initiatoriqn); goto cleanup; } else { VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully", - *ifacename, initiatoriqn); + iface_name, initiatoriqn); } =20 - ret =3D 0; + VIR_STEAL_PTR(*ifacename, iface_name); + + virCommandFree(cmd); + return 0; =20 cleanup: virCommandFree(cmd); - VIR_FREE(temp_ifacename); - if (ret !=3D 0) - VIR_FREE(*ifacename); return ret; } =20 @@ -299,7 +295,7 @@ virISCSIConnection(const char *portal, NULL }; virCommandPtr cmd; - char *ifacename =3D NULL; + VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); virCommandAddArgSet(cmd, extraargv); @@ -339,7 +335,6 @@ virISCSIConnection(const char *portal, =20 cleanup: virCommandFree(cmd); - VIR_FREE(ifacename); =20 return ret; } @@ -390,15 +385,13 @@ virISCSIGetTargets(char **const groups, void *data) { struct virISCSITargetList *list =3D data; - char *target; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, groups[1]) < 0) return -1; =20 - if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) return -1; - } =20 return 0; } @@ -498,8 +491,7 @@ virISCSIScanTargets(const char *portal, size_t *ntargets, char ***targets) { - char *ifacename =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) ifacename =3D NULL; =20 if (ntargets) *ntargets =3D 0; @@ -522,10 +514,8 @@ virISCSIScanTargets(const char *portal, } } =20 - ret =3D virISCSIScanTargetsInternal(portal, ifacename, + return virISCSIScanTargetsInternal(portal, ifacename, persist, ntargets, targets); - VIR_FREE(ifacename); - return ret; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list