From nobody Fri May 3 14:51:53 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; 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 1532806865234448.07207530365054; Sat, 28 Jul 2018 12:41:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03D0C369D0; Sat, 28 Jul 2018 19:41:03 +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 AF4862010CC1; Sat, 28 Jul 2018 19:41: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 2004F18037F5; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJea8l020362 for ; Sat, 28 Jul 2018 15:40:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB3E945B4; Sat, 28 Jul 2018 19:40:36 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D18EC89DFA for ; Sat, 28 Jul 2018 19:40:35 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 17E37307D850 for ; Sat, 28 Jul 2018 19:40:34 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id d17-v6so638424pgv.10 for ; Sat, 28 Jul 2018 12:40:34 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:32 -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=PBInPM3/CZhYbCsC3uTXcIDlFRFSEI7areO8hNhLSQ0=; b=lXKizzq+kq8XeJ4szdEaRMfeR9Pa7hZrk8A+iGSt8DK2Ew6z2y7e7dW3Ur8v7bLnr9 mEnyyqjYvD36w+u/t9k2XBqcPrbV2nlezLG611GYHULIHTSkhNtSqtp5o4sIwO4+gbDV JoV4hDXhftmz5gZSc2MwHTBlsSmIO0pr1iNpKgE0a8Hg9mszjfL7m0PiHye7XlP5RPCz yZHHWbq8nFYDhr0OJE9ATOBPh6WAkvhLMoaAndzJk3Ix4Ju5euhgJO0DCc2QU8CA78UG lwDPSZkk6hn5GRecMnjIJD4r0JtDwChCmSauZPkteFXtP9Bz6+j9llXvLQ9f8EqwmzWa sYnA== 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=PBInPM3/CZhYbCsC3uTXcIDlFRFSEI7areO8hNhLSQ0=; b=aDEkojnJu6XhucZ3YxLdQqgbF07Ls64Exah6n7iaI89Txwm3gji6WBi9JpAZB8SFVd 8MGTxvIoL7M40kvHHKY2VBPq+Hh5fIK143UVznQYF/wepqv0btwujEuosDhQj/WIdmKE R2FPlcrQYPB0jB02rB74tSywPxRxViRSlj5FF9Vn8M54+gOTNbCzRocERAsLu38+bGPN bYBxC8/jLoOLJi9fo0Atq8jj++a5fUjhqYuuL4MFmD9ZMiIzCotOZVyNFidiyFEIJQUY Mhp+nIHEcBkyvOATEdxTXIXvMzchZdLjisDw3Ql2nxup2r4q2FHtouWUrMOHEaKTWOxE ZXnA== X-Gm-Message-State: AOUpUlGJ+2Z4hQzurlfcij+qL6CcXFuLIwhVAk3jc7w3VlRLKv70qP4m ludn9VnpKSfGOJrHaXVaRYf1j2Hw X-Google-Smtp-Source: AAOMgpc5vqNKcBiY4NNY2qrUyvLiijpwnTcXBmE1g6QDUj9ziIiDIPhbhaUljSW8V58Q7mWx/l4omw== X-Received: by 2002:a62:9849:: with SMTP id q70-v6mr11685509pfd.178.1532806833383; Sat, 28 Jul 2018 12:40:33 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:16 +0530 Message-Id: <1532800907-29115-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.48]); Sat, 28 Jul 2018 19:40:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:40:34 +0000 (UTC) for IP:'209.85.215.180' DOMAIN:'mail-pg1-f180.google.com' HELO:'mail-pg1-f180.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.180 mail-pg1-f180.google.com 209.85.215.180 mail-pg1-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 01/32] 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 28 Jul 2018 19:41:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 653b4fd..48f4106 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -88,7 +88,7 @@ virISCSIGetSession(const char *devpath, .session =3D NULL, .devpath =3D devpath, }; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; int exitstatus =3D 0; =20 virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", @@ -109,7 +109,6 @@ virISCSIGetSession(const char *devpath, NULLSTR(error)); =20 cleanup: - VIR_FREE(error); virCommandFree(cmd); return cbdata.session; } @@ -125,10 +124,10 @@ 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; + VIR_AUTOFREE(char *) outbuf =3D NULL; + VIR_AUTOFREE(char *) iface =3D NULL; + VIR_AUTOFREE(char *) iqn =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 @@ -197,9 +196,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,7 +212,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, char **ifacename) { int ret =3D -1, exitstatus =3D -1; - char *temp_ifacename; + VIR_AUTOFREE(char *) temp_ifacename =3D NULL; virCommandPtr cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, @@ -277,7 +273,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, =20 cleanup: virCommandFree(cmd); - VIR_FREE(temp_ifacename); if (ret !=3D 0) VIR_FREE(*ifacename); return ret; @@ -299,7 +294,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 +334,6 @@ virISCSIConnection(const char *portal, =20 cleanup: virCommandFree(cmd); - VIR_FREE(ifacename); =20 return ret; } @@ -390,15 +384,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 +490,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 +513,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 From nobody Fri May 3 14:51:54 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; 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 1532806865508407.1724948109802; Sat, 28 Jul 2018 12:41:05 -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 09059C057F81; Sat, 28 Jul 2018 19:41:03 +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 AE8F16092D; Sat, 28 Jul 2018 19:41: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 1B56918037F3; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJefwP020386 for ; Sat, 28 Jul 2018 15:40:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id F38E06092F; Sat, 28 Jul 2018 19:40:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA01E6092D for ; Sat, 28 Jul 2018 19:40:37 +0000 (UTC) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 1551A3086246 for ; Sat, 28 Jul 2018 19:40:36 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id y10-v6so2877343pfn.8 for ; Sat, 28 Jul 2018 12:40:36 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:34 -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=gdsvi2dR8XZPwUh4n5LSSeV4Xziixcvne2rggYk+FwQ=; b=Lru34AZuhw8/h5Et8vNeDUMxAG8M0A6CfjqaGSTxD2zJ8hE3RC+fV2Tx5vi9eUMgpC /dw6EBBYKoQJIUmd7jjgPpzmnUydqXAcf6DeIaJU2p1aiYMPrDgqRxMvXNiUVBhpmkI+ /1ikUmsg3cW930FtLj87yuv8kXOyQxAGudFuZY1gSVu7c0jolVvYMyHwKWOdJDC+6y4Y XuhGcOFepJMlEEXF0YXDJRraM5XtLQJ2BazKMWk0G9zaIk+92LiAvcuMxxybezIyOHeD IJnyUqQzf+dTDQExcaRSQTpdVKlFuW1ea8aEc3/9eXoEVyM5UFh9iRtTzAqljug2dSqR WzUA== 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=gdsvi2dR8XZPwUh4n5LSSeV4Xziixcvne2rggYk+FwQ=; b=VMMnS5s7ZzlikdWhJPO4+Ul1XjXueTi2T/i/Gzui7izjda8qBWrBmG9FEkdpd9C6qq e3EURM5XOM+OEz3jfX0mmZw27XwQN7AoVHZIubGAtBIYsIYArQ84F8lwbpn8kRDFt++0 R4DAks7gXAsAwtnC2lJZR+hGSA3cM6x0lELlSFBUp3c/MeS34U3m6r2EoeIIrbeHmxXD +qdgmmkbUfmvm+FDbPO2eiu2oefvZ2tJlNuv5LCiEtHYq3H5FIi52+iftAoV35Ha7CKO fDvz9TW6IcPiDU3ehiQACnhdSdCCln0EGWWwogqSPwM4nGnOCBgkOksNxNjq4PJHVPSu NAPg== X-Gm-Message-State: AOUpUlE7pLfcbM6drIudMXazY50dM8snnG9mAIyRtMmpuXWmw4pJuNPc lEQJX8dR7e0IZBlQjhrOW3Gt2x3r X-Google-Smtp-Source: AAOMgpekZp4+hyU9scKBOIoB0ylC4ptTML6CTTzNG3q7Sc+lEbFn4B18D1cDckDASlSIgzNgrg/wbw== X-Received: by 2002:a62:1815:: with SMTP id 21-v6mr11777936pfy.227.1532806835371; Sat, 28 Jul 2018 12:40:35 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:17 +0530 Message-Id: <1532800907-29115-3-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.49]); Sat, 28 Jul 2018 19:40:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:40:36 +0000 (UTC) for IP:'209.85.210.174' DOMAIN:'mail-pf1-f174.google.com' HELO:'mail-pf1-f174.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.210.174 mail-pf1-f174.google.com 209.85.210.174 mail-pf1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 02/32] util: iscsi: use VIR_AUTOPTR for aggregate 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.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.32]); Sat, 28 Jul 2018 19:41:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions 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 | 68 +++++++++++++++++--------------------------------= ---- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 48f4106..81404f8 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -91,7 +91,7 @@ virISCSIGetSession(const char *devpath, VIR_AUTOFREE(char *) error =3D NULL; int exitstatus =3D 0; =20 - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode= ", "session", NULL); virCommandSetErrorBuffer(cmd, &error); =20 @@ -101,15 +101,13 @@ virISCSIGetSession(const char *devpath, vars, virISCSIExtractSession, &cbdata, NULL, &exitstatus) < 0) - goto cleanup; + return NULL; =20 if (cbdata.session =3D=3D NULL && !probe) virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find iscsiadm session: %s"), NULLSTR(error)); =20 - cleanup: - virCommandFree(cmd); return cbdata.session; } =20 @@ -128,7 +126,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, VIR_AUTOFREE(char *) outbuf =3D NULL; VIR_AUTOFREE(char *) iface =3D NULL; VIR_AUTOFREE(char *) iqn =3D NULL; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 *ifacename =3D NULL; @@ -196,7 +194,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - virCommandFree(cmd); return ret; =20 error: @@ -213,7 +210,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, { int ret =3D -1, exitstatus =3D -1; VIR_AUTOFREE(char *) temp_ifacename =3D NULL; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -272,7 +269,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, ret =3D 0; =20 cleanup: - virCommandFree(cmd); if (ret !=3D 0) VIR_FREE(*ifacename); return ret; @@ -285,7 +281,6 @@ virISCSIConnection(const char *portal, const char *target, const char **extraargv) { - int ret =3D -1; const char *const baseargv[] =3D { ISCSIADM, "--mode", "node", @@ -293,7 +288,7 @@ virISCSIConnection(const char *portal, "--targetname", target, NULL }; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); @@ -306,7 +301,7 @@ virISCSIConnection(const char *portal, break; case IQN_MISSING: if (virStorageBackendCreateIfaceIQN(initiatoriqn, &ifacename) = !=3D 0) - goto cleanup; + return -1; /* * iscsiadm doesn't let you send commands to the Interface IQN, * unless you've first issued a 'sendtargets' command to the @@ -317,25 +312,20 @@ virISCSIConnection(const char *portal, */ if (virISCSIScanTargetsInternal(portal, ifacename, true, NULL, NULL) < 0) - goto cleanup; + return -1; =20 break; case IQN_ERROR: default: - goto cleanup; + return -1; } virCommandAddArgList(cmd, "--interface", ifacename, NULL); } =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - - return ret; + return 0; } =20 =20 @@ -362,14 +352,12 @@ virISCSIConnectionLogout(const char *portal, int virISCSIRescanLUNs(const char *session) { - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "session", "-r", session, "-R", NULL); - int ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -419,8 +407,7 @@ virISCSIScanTargetsInternal(const char *portal, int vars[] =3D { 2 }; struct virISCSITargetList list; size_t i; - int ret =3D -1; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, @@ -446,7 +433,7 @@ virISCSIScanTargetsInternal(const char *portal, vars, virISCSIGetTargets, &list, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (ntargetsret && targetsret) { *ntargetsret =3D list.ntargets; @@ -457,10 +444,7 @@ virISCSIScanTargetsInternal(const char *portal, VIR_FREE(list.targets); } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -538,9 +522,8 @@ int virISCSINodeNew(const char *portal, const char *target) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -553,20 +536,17 @@ virISCSINodeNew(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed new node mode for target '%s'"), target); - goto cleanup; + return -1; } =20 if (status !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s failed new mode for target '%s' with status '= %d'"), ISCSIADM, target, status); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -576,9 +556,8 @@ virISCSINodeUpdate(const char *portal, const char *name, const char *value) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -594,11 +573,8 @@ virISCSINodeUpdate(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update '%s' of node mode for target '%= s'"), name, target); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806851875662.5443104431266; Sat, 28 Jul 2018 12:40:51 -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 A851E3082137; Sat, 28 Jul 2018 19:40:44 +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 779C4600C0; Sat, 28 Jul 2018 19:40:44 +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 F41E24A460; Sat, 28 Jul 2018 19:40:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJedc6020377 for ; Sat, 28 Jul 2018 15:40:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7BB689DFA; Sat, 28 Jul 2018 19:40:39 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF9BF45B4 for ; Sat, 28 Jul 2018 19:40:39 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 33FE1C057F80 for ; Sat, 28 Jul 2018 19:40:38 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id e6-v6so5082197pgv.2 for ; Sat, 28 Jul 2018 12:40:38 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:36 -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=Aw274DHQEBqc36nufgd8qkOcmIIm98sd14Wp/DRn77g=; b=vE3CDKtkRMvWZUrKgvw69z0DaZWzL91JZrNMVnONaNFyJz0a5BTUvs4y533E+mESyB r1CdL1fetCKZ7L3yiuC1B44qColW1sT/bPWAjRMGpb6559J7KjOfrinSSCi2fAKF5hY3 keewCsV3ZvxoOghD7c7lvg4741/CujaAuHMbsnXyAIyAPyC2CsCHF+T/h0Qy+TxQo0aV 0Qg3A8Sqw6wVGVoInPZvXY3X77My0Stqbh1D2K+8bOLw1qw5vhNZrrD4tW4Yga1bhwKu f1f9uJImLryfdGTaOxWdTO+0vfXMWPymUyioOV9MvXTX+VGo4s6zDp2HexbsqpSEfChl JdEA== 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=Aw274DHQEBqc36nufgd8qkOcmIIm98sd14Wp/DRn77g=; b=i3uLFzycdeKn1AfJjvGqnqkntWAt6n4oJj9ZlrmhLzUCyOLkfl/y11yDEWbdyGyCRP hx7uNe74UXsqHyyUOHYhd/3t78IB1N+wRB8BS5gJk7MoMdiFoGu41DN24UegybQiueML qnyQKLUnYSVSYoPy2/VYB2q1jR3QMv1F9Bkq7YzCgTbGcR+eu8upfsB25bwkcEKosPuJ 78DiY6fd7xX9Xce+admxVWQZ0AoRM509oiBj6z1KGz2P0jsrzzWyXUPR93ciZPFtzi1o 63As+kG87TgwTJ5hh1unQBBm2WEZZGugPwGIRuT9B7tgG2arD66WodFlu8SIJwSBcsgb So1g== X-Gm-Message-State: AOUpUlFo62JAhYzYWIqXlPvfHwFEu1PAC9KaM9UhvfYI8R87DymUYeIs SZD2auuTc5L+7wky9S90ge615Omi X-Google-Smtp-Source: AAOMgpe1uwI+9OHeK6tZ5s+qPHa0fmdWUJKhkKG44E9lbLGY5JjsUDQ3mDqbIBFbci/Q6A0S4jtTsw== X-Received: by 2002:a62:e30c:: with SMTP id g12-v6mr11806979pfh.25.1532806837480; Sat, 28 Jul 2018 12:40:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:18 +0530 Message-Id: <1532800907-29115-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.32]); Sat, 28 Jul 2018 19:40:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 28 Jul 2018 19:40:38 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 03/32] util: netdevbridge: 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.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.42]); Sat, 28 Jul 2018 19:40:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 --- src/util/virnetdevbridge.c | 45 +++++++++++++++---------------------------= --- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index e46ac35..bf30d7c 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -126,8 +126,7 @@ static int virNetDevBridgeSet(const char *brname, int fd, /* control socket */ struct ifreq *ifr) /* pre-filled bridge= name */ { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname= ) < 0) return -1; @@ -138,7 +137,7 @@ static int virNetDevBridgeSet(const char *brname, if (virFileWriteStr(path, valuestr, 0) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } else { unsigned long paramid; @@ -149,21 +148,18 @@ static int virNetDevBridgeSet(const char *brname, } else { virReportSystemError(EINVAL, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } unsigned long args[] =3D { paramid, value, 0, 0 }; ifr->ifr_data =3D (char*)&args; if (ioctl(fd, SIOCDEVPRIVATE, ifr) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -171,7 +167,7 @@ static int virNetDevBridgeGet(const char *brname, const char *paramname, /* sysfs param name = */ unsigned long *value) /* current value */ { - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; int ret =3D -1; int fd =3D -1; struct ifreq ifr; @@ -180,7 +176,7 @@ static int virNetDevBridgeGet(const char *brname, return -1; =20 if (virFileExists(path)) { - char *valuestr; + VIR_AUTOFREE(char *) valuestr =3D NULL; if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) goto cleanup; @@ -189,10 +185,8 @@ static int virNetDevBridgeGet(const char *brname, virReportSystemError(EINVAL, _("Unable to get bridge %s %s"), brname, paramname); - VIR_FREE(valuestr); goto cleanup; } - VIR_FREE(valuestr); } else { struct __bridge_info info; unsigned long args[] =3D { BRCTL_GET_BRIDGE_INFO, (unsigned long)&= info, 0, 0 }; @@ -221,7 +215,6 @@ static int virNetDevBridgeGet(const char *brname, ret =3D 0; cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(path); return ret; } #endif /* __linux__ */ @@ -233,7 +226,7 @@ virNetDevBridgePortSet(const char *brname, const char *paramname, unsigned long value) { - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char valuestr[INT_BUFSIZE_BOUND(value)]; int ret =3D -1; =20 @@ -254,7 +247,6 @@ virNetDevBridgePortSet(const char *brname, brname, ifname, paramname, valuestr); } =20 - VIR_FREE(path); return ret; } =20 @@ -265,29 +257,24 @@ virNetDevBridgePortGet(const char *brname, const char *paramname, unsigned long *value) { - char *path =3D NULL; - char *valuestr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) valuestr =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, paramname) < 0) return -1; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) = < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { virReportSystemError(EINVAL, _("Unable to get bridge %s port %s %s"), brname, ifname, paramname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(valuestr); - return ret; + return 0; } =20 =20 @@ -430,7 +417,7 @@ virNetDevBridgeCreate(const char *brname) /* use a netlink RTM_NEWLINK message to create the bridge */ const char *type =3D "bridge"; int rc =3D -1; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; @@ -495,7 +482,6 @@ virNetDevBridgeCreate(const char *brname) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1069,7 +1055,7 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, unsigned int flags, bool isAdd) { int ret =3D -1; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen; struct nl_msg *nl_msg; @@ -1142,7 +1128,6 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, ret =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return ret; =20 malformed_resp: --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806869863819.2046017773985; Sat, 28 Jul 2018 12:41:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50594308FB90; Sat, 28 Jul 2018 19:41:07 +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 1F1EA2010CED; Sat, 28 Jul 2018 19:41:07 +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 BC9FE4A463; Sat, 28 Jul 2018 19:41:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJej9d020402 for ; Sat, 28 Jul 2018 15:40:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id A5921782C6; Sat, 28 Jul 2018 19:40:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E2857555C for ; Sat, 28 Jul 2018 19:40:42 +0000 (UTC) Received: from mail-pl0-f52.google.com (mail-pl0-f52.google.com [209.85.160.52]) (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 013F48553D for ; Sat, 28 Jul 2018 19:40:42 +0000 (UTC) Received: by mail-pl0-f52.google.com with SMTP id e11-v6so3726467plb.3 for ; Sat, 28 Jul 2018 12:40:41 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:39 -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=zD4K7A56pqBMV1DacCHCCui9ATMkWwkbIvMfOiR+stc=; b=PXN67kpp5+adgSMSA4/KH/B49YIKADmB47uDpStH7tvSh52vzikvAeLEx69/uZoCrT FBoWud/tRTE7h9LfAi8tBcEdqx2m1XSlsYw7K72YQ0cFaYyaY8YnYvqlJVQ0KXGpJiSr mGxUWaOD8sV2EwjTENsOaImauIsElln0yqNvzIEKt5HowcDerGnhJwVMx1VWx92NR4nc ULgudZOw22I0r29h1V2UXwEu93m2W7nstastfURKuLiO+HMfDbAVdy/m254BrkbsxRXk UqKyAd2sfm26jW0K4KfMi+XHWaHzxbX3yCd1BToy1gw24lKfiqlHpmKo/M62jcVqH2UE 1rxA== 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=zD4K7A56pqBMV1DacCHCCui9ATMkWwkbIvMfOiR+stc=; b=XppnbvdROcAJd3Cv3s4ApJ7RlVeH9+G3gqTrC1ozHg3C5X9rC7TNQLcF71+qALmPfB kSJHawGBpK5zwopnJZAwl+ueOcRTk9O/OIiTK9DsrxF/jXjaejUPBUJ6RRgzu8vR0J0A FN1j+LHJYDE9x3NG1zAfXbFowG1hDwlSb6Ch4qqm+U+e7IaTFsiWmY6BOR+FReo5slDq qN4EyPFHrKB9lOCF2+w/A/Ul0jcRecUYhyoIGVpWo2BJb8uPTAUw/BeQ97I5XthiNZCv Z+w6mL5FrFRSMleCLmbpY7uumvcM0+47XBpIaEoY5YMSsveK7JGLP6NVGxdogIVOYC4z 8qHg== X-Gm-Message-State: AOUpUlH5npykW+TpkpbkHMFin6i9kKtQWLN5WKKRvRk2K7uk/vXXJ8Bk dByYlJX21iAGD5lfEk5uIKEaY4bb X-Google-Smtp-Source: AAOMgpcWJZtT9F9OiIN6bnL28dnBargSsmEHrBamiyRX8WxAG2lD460R42YOf7pkNB6FE8UuQ+w4eQ== X-Received: by 2002:a17:902:18a:: with SMTP id b10-v6mr10872372plb.62.1532806840249; Sat, 28 Jul 2018 12:40:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:19 +0530 Message-Id: <1532800907-29115-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.28]); Sat, 28 Jul 2018 19:40:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 28 Jul 2018 19:40:42 +0000 (UTC) for IP:'209.85.160.52' DOMAIN:'mail-pl0-f52.google.com' HELO:'mail-pl0-f52.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.160.52 mail-pl0-f52.google.com 209.85.160.52 mail-pl0-f52.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 04/32] util: macaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 28 Jul 2018 19:41:07 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virMacAddrPtr is declared using VIR_AUTOPTR, the function virMacAddrFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virmacaddr.c | 6 ++++++ src/util/virmacaddr.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 7afe032..e739775 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -252,3 +252,9 @@ virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_= BUFLEN]) { return memcmp(virMacAddrBroadcastAddrRaw, s, sizeof(*s)) =3D=3D 0; } + +void +virMacAddrFree(virMacAddrPtr addr) +{ + VIR_FREE(addr); +} diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index d0dd4a4..39dd51b 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -25,6 +25,7 @@ # define __VIR_MACADDR_H__ =20 # include "internal.h" +# include "viralloc.h" =20 # define VIR_MAC_BUFLEN 6 # define VIR_MAC_HEXLEN (VIR_MAC_BUFLEN * 2) @@ -64,5 +65,8 @@ int virMacAddrParseHex(const char* str, bool virMacAddrIsUnicast(const virMacAddr *addr); bool virMacAddrIsMulticast(const virMacAddr *addr); bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]); +void virMacAddrFree(virMacAddrPtr addr); + +VIR_DEFINE_AUTOPTR_FUNC(virMacAddr, virMacAddrFree) =20 #endif /* __VIR_MACADDR_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 15328068740131003.6929053125705; Sat, 28 Jul 2018 12:41:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6EE730820EA; Sat, 28 Jul 2018 19:41:11 +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 9B5A1CFC00; Sat, 28 Jul 2018 19:41:11 +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 48DE418037F1; Sat, 28 Jul 2018 19:41:11 +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 w6SJekM3020407 for ; Sat, 28 Jul 2018 15:40:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8449600C8; Sat, 28 Jul 2018 19:40:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA029600C5 for ; Sat, 28 Jul 2018 19:40:44 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (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 8F12A307D854 for ; Sat, 28 Jul 2018 19:40:43 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id t17-v6so3720391ply.13 for ; Sat, 28 Jul 2018 12:40:43 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:42 -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=YUFwHnCZOccH4d0K4xsZYXlIl6Kzvlq02ElY4vYAHG8=; b=kQQ4kZ+SKRXdoNWbYgJI1fO2gLZObXN/AmcmZt2TX7LODMSZcCQmAn0jTqChKi0bWY pnDFncorpAlQolmZDPz9V7rIqOLIN1xvonwK1iyjl+/M0ujQ3U+XEIL2KXtJnW/MvDof AUnuQJMnARKT2yJlI1pJx4NuOzDelv3xmHv6At89B5wp+NE8zWMw9LlE/bsh1RtcCesw xo+bEXy8P1ehZemmt7smEsSBn4wiHWD4hhSguAq7KsPmK/abM4PSiEuaaJVjAyT7eymM yHLjZu9GbMgmz0tIz7lhPUuYbsySfp6K9vGGLVdOzt22+3vAbQUoPa7ojOq8nNHGW6K8 /AMA== 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=YUFwHnCZOccH4d0K4xsZYXlIl6Kzvlq02ElY4vYAHG8=; b=uFXm54NnU6Mi4AUGKyXwpHESD95uiMyz69rL3c4+lXBBulOzp28NYw4UhXgQ+DeN5k Re+wAhmrUXKy2bvlgdSID6OX5daHY0kqL2oJ81DsnwOlGEv4kTeye+CXSSrR/oXOg87G 9XF1vxqY/Lb+kyBMO12M3JTL4OdIs8ozZXkk/IEEXNhIWgfrNGeHNxLrlv/Mws0tR5gk AaZUmRTT9RZ+02z2lb1+lhMEkGPXGP2qQcY+/hlRHLpENpP+FI1l+pBKSwx6gOL2zQx9 1pOna5pasNG9F+8ZqajNO4p1WDWThiCHvGqSqLyi57QR+KT0Y1EPspIbUjWRUvSA1zXu P3ag== X-Gm-Message-State: AOUpUlFDpFcMnd999hoPULMZnIwFrfnXH8LvLs7GtpPtt5NKIUJNGNPs FJePKcGsMBIiEe5oXFADuSoh3jip X-Google-Smtp-Source: AAOMgpdDnVv6t7n4oPEziLM8tf7EQsc8UbHyzOcj0Z/yPxduMbYB0gQvFEd+ykvmu8o7wxf4KSz2ug== X-Received: by 2002:a17:902:6105:: with SMTP id t5-v6mr10788512plj.92.1532806842786; Sat, 28 Jul 2018 12:40:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:20 +0530 Message-Id: <1532800907-29115-6-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.48]); Sat, 28 Jul 2018 19:40:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:40:43 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 05/32] util: netdev: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:41:12 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virNetDevRxFilterPtr and virNetDevMcastEntryPtr are declared using VIR_AUTOPTR, the functions virNetDevRxFilterFree and virNetDevMcastEntryFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdev.c | 9 ++++++++- src/util/virnetdev.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 0777eca..9eca786 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -29,7 +29,6 @@ #include "virfile.h" #include "virerror.h" #include "vircommand.h" -#include "viralloc.h" #include "virpci.h" #include "virlog.h" #include "virstring.h" @@ -120,6 +119,14 @@ struct _virNetDevMcastEntry { virMacAddr macaddr; }; =20 +static void +virNetDevMcastEntryFree(virNetDevMcastEntryPtr entry) +{ + VIR_FREE(entry); +} + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevMcastEntry, virNetDevMcastEntryFree) + typedef struct _virNetDevMcastList virNetDevMcastList; typedef virNetDevMcastList *virNetDevMcastListPtr; struct _virNetDevMcastList { diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 71eaf45..8860ea1 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -30,6 +30,7 @@ # include "virmacaddr.h" # include "virpci.h" # include "virnetdevvlan.h" +# include "viralloc.h" =20 # ifdef HAVE_STRUCT_IFREQ typedef struct ifreq virIfreq; @@ -313,4 +314,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, =20 int virNetDevRunEthernetScript(const char *ifname, const char *script) ATTRIBUTE_NOINLINE; + +VIR_DEFINE_AUTOPTR_FUNC(virNetDevRxFilter, virNetDevRxFilterFree) + #endif /* __VIR_NETDEV_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806854451375.65254917614857; Sat, 28 Jul 2018 12:40:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05E2330832CB; Sat, 28 Jul 2018 19:40:52 +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 BA2B41001F5B; Sat, 28 Jul 2018 19:40:50 +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 671E74A46C; Sat, 28 Jul 2018 19:40:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJel57020415 for ; Sat, 28 Jul 2018 15:40:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id DA18FCFBFA; Sat, 28 Jul 2018 19:40:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1B1CCFBF7 for ; Sat, 28 Jul 2018 19:40:47 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (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 F0BC68553D for ; Sat, 28 Jul 2018 19:40:45 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id a11-v6so5079105pgw.6 for ; Sat, 28 Jul 2018 12:40:45 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:44 -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=/ZmdvgST4OeylzCc+nMAf/YJN2foe4GIl42YDME3l6A=; b=LXZLcmTw7u589eSGZvxWl6gIWVcyuc9BATBzd8gQAtcnoWn8eYoJ6XLu63eJc3ZKS9 ePlui7IzzuKRGmiXigit0rKWXFMEC+J730Q7xnHj/7I6z//kNpHBpT+E/cWGTg40Flc+ NWgUgR0EGyIA1Cr0TbOBM78D38tCmSUVxK5mY2cpz1BqAHnLrrdwNfasNgOPS1hgShp8 OzSnM8ooLhGAjWldCG4xq7+lzPva8+kV8TgBcPoaSYvBCWvsl21bdfPJbxBkgarfNPhE R/cg+9C3xEaIDCPZGo/chPUJFSTz17gILsX8yc51eQkKGRasallaXWpH5rLZf8MFBLn+ +9nQ== 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=/ZmdvgST4OeylzCc+nMAf/YJN2foe4GIl42YDME3l6A=; b=S0cyL3/APRWCDeDhafiBZj59X5+XnY6NdUN5jQnOnpCj3GfXkiTzKGihV61Kt/FusP a4KQ+ET1ISCQS2PhVCYhU+uD5u5zAG3ZKdHpaprJguiUFhnEHkl6APScVZ3jBWIfWcrX WBpHirJpRW8i9OUBxjtNP2TIjM6aHVXeKQjeLxDf95VeMcB1t/+UTQeeRZFalfsBQEqE b5MBBloT84gOcNN/EiIvOlTUUSbi4NLQizg1+Sy4xXGVtvZN7Vj2XiD9uNC24tmJMkew RmOZ5ia3ZgX8J010Cm2jqkF4anYgqxs053kwXv1T4hlrzj7MayR/2uersJfDCzDoYqi7 3v+Q== X-Gm-Message-State: AOUpUlEm5kTIw2WbYdYt7/Kvbb8s9NomDTt6fwR6yeMs5gWv52hX6411 avQEA2LSJfcUKjDHVo667+wffGrO X-Google-Smtp-Source: AAOMgpe2L6tEiPgzT2dTaEGcGbP64lthpaCHxq8mp/M/PpZhcDQUuITgAzJkQgO3uOl79WMj43Cd4w== X-Received: by 2002:a63:af14:: with SMTP id w20-v6mr11022501pge.47.1532806845158; Sat, 28 Jul 2018 12:40:45 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:21 +0530 Message-Id: <1532800907-29115-7-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.28]); Sat, 28 Jul 2018 19:40:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 28 Jul 2018 19:40:46 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 06/32] util: netdev: 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:40:52 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 --- src/util/virnetdev.c | 276 ++++++++++++++++++-----------------------------= ---- 1 file changed, 96 insertions(+), 180 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 9eca786..7653f8b 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -535,10 +535,9 @@ int virNetDevSetMTUFromDevice(const char *ifname, */ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) { - int ret =3D -1; - char *pid =3D NULL; - char *phy =3D NULL; - char *phy_path =3D NULL; + VIR_AUTOFREE(char *) pid =3D NULL; + VIR_AUTOFREE(char *) phy =3D NULL; + VIR_AUTOFREE(char *) phy_path =3D NULL; int len; =20 if (virAsprintf(&pid, "%lld", (long long) pidInNs) =3D=3D -1) @@ -546,7 +545,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pid= InNs) =20 /* The 802.11 wireless devices only move together with their PHY. */ if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0) - goto cleanup; + return -1; =20 if ((len =3D virFileReadAllQuiet(phy_path, 1024, &phy)) <=3D 0) { /* Not a wireless device. */ @@ -556,7 +555,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pid= InNs) =20 argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; =20 } else { const char *argv[] =3D { @@ -569,15 +568,10 @@ int virNetDevSetNamespace(const char *ifname, pid_t p= idInNs) argv[2] =3D phy; argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(phy_path); - VIR_FREE(phy); - VIR_FREE(pid); - return ret; + return 0; } =20 #if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ) @@ -969,25 +963,21 @@ int virNetDevGetIndex(const char *ifname ATTRIBUTE_UN= USED, int virNetDevGetMaster(const char *ifname, char **master) { - int ret =3D -1; - void *nlData =3D NULL; + VIR_AUTOFREE(void *) nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; =20 *master =3D NULL; =20 if (virNetlinkDumpLink(ifname, -1, &nlData, tb, 0, 0) < 0) - goto cleanup; + return -1; =20 if (tb[IFLA_MASTER]) { if (!(*master =3D virNetDevGetName(*(int *)RTA_DATA(tb[IFLA_MASTER= ])))) - goto cleanup; + return -1; } =20 VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(no= ne)"); - ret =3D 0; - cleanup: - VIR_FREE(nlData); - return ret; + return 0; } =20 =20 @@ -1168,37 +1158,31 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_lin= k, const char *ifname, static bool virNetDevIsPCIDevice(const char *devpath) { - char *subsys_link =3D NULL; - char *abs_path =3D NULL; + VIR_AUTOFREE(char *) subsys_link =3D NULL; + VIR_AUTOFREE(char *) abs_path =3D NULL; char *subsys =3D NULL; - bool ret =3D false; =20 if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0) return false; =20 if (!virFileExists(subsys_link)) - goto cleanup; + return false; =20 if (virFileResolveLink(subsys_link, &abs_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device subsystem symlink %s"), subsys_link); - goto cleanup; + return false; } =20 subsys =3D last_component(abs_path); - ret =3D STRPREFIX(subsys, "pci"); - - cleanup: - VIR_FREE(subsys_link); - VIR_FREE(abs_path); - return ret; + return STRPREFIX(subsys, "pci"); } =20 static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - char *vfSysfsDevicePath =3D NULL; + VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; virPCIDeviceAddressPtr vfPCIAddr =3D NULL; virPCIDevicePtr vfPCIDevice =3D NULL; =20 @@ -1216,7 +1200,6 @@ virNetDevGetPCIDevice(const char *devName) vfPCIAddr->slot, vfPCIAddr->function); =20 cleanup: - VIR_FREE(vfSysfsDevicePath); VIR_FREE(vfPCIAddr); =20 return vfPCIDevice; @@ -1241,25 +1224,20 @@ int virNetDevGetPhysPortID(const char *ifname, char **physPortID) { - int ret =3D -1; - char *physPortIDFile =3D NULL; + VIR_AUTOFREE(char *) physPortIDFile =3D NULL; =20 *physPortID =3D NULL; =20 if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) - goto cleanup; + return -1; =20 /* a failure to read just means the driver doesn't support - * phys_port_id, so set success now and ignore the return from - * virFileReadAllQuiet(). + * phys_port_id, so ignore the return from virFileReadAllQuiet() + * and return success. */ - ret =3D 0; - ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); =20 - cleanup: - VIR_FREE(physPortIDFile); - return ret; + return 0; } =20 =20 @@ -1282,10 +1260,11 @@ virNetDevGetVirtualFunctions(const char *pfname, { int ret =3D -1; size_t i; - char *pf_sysfs_device_link =3D NULL; - char *pci_sysfs_device_link =3D NULL; - char *pciConfigAddr =3D NULL; - char *pfPhysPortID =3D NULL; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pci_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pciConfigAddr =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; + VIR_AUTOFREE(char **) tempVfname =3D NULL; =20 *virt_fns =3D NULL; *n_vfname =3D 0; @@ -1333,13 +1312,9 @@ virNetDevGetVirtualFunctions(const char *pfname, =20 cleanup: if (ret < 0) { - VIR_FREE(*vfname); + VIR_STEAL_PTR(tempVfname, *vfname); VIR_FREE(*virt_fns); } - VIR_FREE(pfPhysPortID); - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(pci_sysfs_device_link); - VIR_FREE(pciConfigAddr); return ret; } =20 @@ -1355,17 +1330,12 @@ virNetDevGetVirtualFunctions(const char *pfname, int virNetDevIsVirtualFunction(const char *ifname) { - char *if_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) if_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(if_sysfs_device_link); - - VIR_FREE(if_sysfs_device_link); - - return ret; + return virPCIIsVirtualFunction(if_sysfs_device_link); } =20 /** @@ -1383,25 +1353,19 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname, int *vf_index) { - char *pf_sysfs_device_link =3D NULL, *vf_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - return ret; + return -1; =20 - if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) { - VIR_FREE(pf_sysfs_device_link); - return ret; - } + if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, + return virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, vf_sysfs_device_link, vf_index); =20 - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(vf_sysfs_device_link); - - return ret; } =20 /** @@ -1417,19 +1381,18 @@ virNetDevGetVirtualFunctionIndex(const char *pfname= , const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { - char *physfn_sysfs_path =3D NULL; - char *vfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) physfn_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vfPhysPortID =3D NULL; =20 if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) - goto cleanup; + return -1; =20 if (virPCIGetNetName(physfn_sysfs_path, 0, vfPhysPortID, pfname) < 0) { - goto cleanup; + return -1; } =20 if (!*pfname) { @@ -1439,14 +1402,10 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) virReportError(VIR_ERR_INTERNAL_ERROR, _("The PF device for VF %s has no network device na= me"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(vfPhysPortID); - VIR_FREE(physfn_sysfs_path); - return ret; + return 0; } =20 =20 @@ -1470,26 +1429,25 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) { - char *virtfnName =3D NULL; - char *virtfnSysfsPath =3D NULL; - char *pfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) virtfnName =3D NULL; + VIR_AUTOFREE(char *) virtfnSysfsPath =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; =20 /* a VF may have multiple "ports", each one having its own netdev, * and each netdev having a different phys_port_id. Be sure we get * the VF netdev with a phys_port_id matchine that of pfname */ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0) - goto cleanup; + return -1; =20 /* this provides the path to the VF's directory in sysfs, * e.g. "/sys/class/net/enp2s0f0/virtfn3" */ if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0) - goto cleanup; + return -1; =20 /* and this gets the netdev name associated with it, which is a * directory entry in [virtfnSysfsPath]/net, @@ -1498,14 +1456,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); - - cleanup: - VIR_FREE(virtfnName); - VIR_FREE(virtfnSysfsPath); - VIR_FREE(pfPhysPortID); - - return ret; + return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); } =20 =20 @@ -1522,13 +1473,14 @@ int virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, int *vf) { - char *pf_sysfs_path =3D NULL, *vf_sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) tempPfname =3D NULL; =20 *pfname =3D NULL; =20 if (virNetDevGetPhysicalFunction(vfname, pfname) < 0) - return ret; + return -1; =20 if (virNetDevSysfsFile(&pf_sysfs_path, *pfname, "device") < 0) goto cleanup; @@ -1536,16 +1488,12 @@ virNetDevGetVirtualFunctionInfo(const char *vfname,= char **pfname, if (virNetDevSysfsFile(&vf_sysfs_path, vfname, "device") < 0) goto cleanup; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf= ); + return virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf); =20 cleanup: - if (ret < 0) - VIR_FREE(*pfname); + VIR_STEAL_PTR(tempPfname, *pfname); =20 - VIR_FREE(vf_sysfs_path); - VIR_FREE(pf_sysfs_path); - - return ret; + return -1; } =20 #else /* !__linux__ */ @@ -1657,7 +1605,7 @@ virNetDevSetVfConfig(const char *ifname, int vf, { int rc =3D -1; char macstr[VIR_MAC_STRING_BUFLEN]; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; struct nl_msg *nl_msg; @@ -1769,7 +1717,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, vlanid, rc < 0 ? "Fail" : "Success"); =20 nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1843,19 +1790,15 @@ virNetDevGetVfConfig(const char *ifname, int vf, vi= rMacAddrPtr mac, int *vlanid) { int rc =3D -1; - void *nlData =3D NULL; + VIR_AUTOFREE(void *) nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; int ifindex =3D -1; =20 rc =3D virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0); if (rc < 0) - goto cleanup; + return rc; =20 - rc =3D virNetDevParseVfConfig(tb, vf, mac, vlanid); - - cleanup: - VIR_FREE(nlData); - return rc; + return virNetDevParseVfConfig(tb, vf, mac, vlanid); } =20 =20 @@ -1914,13 +1857,13 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; =20 if (vf >=3D 0) { @@ -2030,10 +1973,6 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2069,10 +2008,10 @@ virNetDevReadNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; - char *filePath =3D NULL; - char *fileStr =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; @@ -2245,10 +2184,6 @@ virNetDevReadNetConfig(const char *linkdev, int vf, VIR_FREE(*vlan); } =20 - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2282,8 +2217,8 @@ virNetDevSetNetConfig(const char *linkdev, int vf, int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; int vlanTag =3D -1; virPCIDevicePtr vfPCIDevice =3D NULL; =20 @@ -2462,8 +2397,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); virPCIDeviceFree(vfPCIDevice); return ret; } @@ -2543,28 +2476,27 @@ int virNetDevGetLinkInfo(const char *ifname, virNetDevIfLinkPtr lnk) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *tmp; int tmp_state; unsigned int tmp_speed; =20 if (virNetDevSysfsFile(&path, ifname, "operstate") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) { virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (!(tmp =3D strchr(buf, '\n'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 *tmp =3D '\0'; @@ -2575,7 +2507,7 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->state =3D tmp_state; @@ -2586,26 +2518,24 @@ virNetDevGetLinkInfo(const char *ifname, * speed if that's the case. */ if (lnk->state !=3D VIR_NETDEV_IF_STATE_UP) { lnk->speed =3D 0; - ret =3D 0; - goto cleanup; + return 0; } =20 VIR_FREE(path); VIR_FREE(buf); =20 if (virNetDevSysfsFile(&path, ifname, "speed") < 0) - goto cleanup; + return -1; =20 if (virFileReadAllQuiet(path, 1024, &buf) < 0) { /* Some devices doesn't report speed, in which case we get EINVAL = */ - if (errno =3D=3D EINVAL) { - ret =3D 0; - goto cleanup; - } + if (errno =3D=3D EINVAL) + return 0; + virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (virStrToLong_ui(buf, &tmp, 10, &tmp_speed) < 0 || @@ -2613,16 +2543,12 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->speed =3D tmp_speed; =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 #else @@ -2830,7 +2756,7 @@ static int virNetDevGetMcastList(const char *ifname, virNetDevMcastListPtr mcast) { char *cur =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *next =3D NULL; int ret =3D -1, len; virNetDevMcastEntryPtr entry =3D NULL; @@ -2866,7 +2792,6 @@ static int virNetDevGetMcastList(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(buf); VIR_FREE(entry); =20 return ret; @@ -3006,10 +2931,8 @@ static int virNetDevRDMAFeature(const char *ifname, virBitmapPtr *out) { - char *eth_devpath =3D NULL; - char *ib_devpath =3D NULL; - char *eth_res_buf =3D NULL; - char *ib_res_buf =3D NULL; + VIR_AUTOFREE(char *) eth_devpath =3D NULL; + VIR_AUTOFREE(char *) eth_res_buf =3D NULL; DIR *dirp =3D NULL; struct dirent *dp; int ret =3D -1; @@ -3028,6 +2951,9 @@ virNetDevRDMAFeature(const char *ifname, goto cleanup; =20 while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { + VIR_AUTOFREE(char *) ib_devpath =3D NULL; + VIR_AUTOFREE(char *) ib_res_buf =3D NULL; + if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resou= rce", dp->d_name) < 0) continue; @@ -3036,17 +2962,11 @@ virNetDevRDMAFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA)); break; } - VIR_FREE(ib_devpath); - VIR_FREE(ib_res_buf); } ret =3D 0; =20 cleanup: VIR_DIR_CLOSE(dirp); - VIR_FREE(eth_devpath); - VIR_FREE(ib_devpath); - VIR_FREE(eth_res_buf); - VIR_FREE(ib_res_buf); return ret; } =20 @@ -3205,7 +3125,7 @@ static uint32_t virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; @@ -3245,7 +3165,6 @@ virNetDevGetFamilyId(const char *family_name) =20 cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return family_id; } =20 @@ -3265,13 +3184,13 @@ virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; - char *pfname =3D NULL; + VIR_AUTOFREE(char *) pfname =3D NULL; int is_vf =3D -1; int ret =3D -1; uint32_t family_id; @@ -3333,8 +3252,6 @@ virNetDevSwitchdevFeature(const char *ifname, cleanup: nlmsg_free(nl_msg); virPCIDeviceFree(pci_device_ptr); - VIR_FREE(resp); - VIR_FREE(pfname); return ret; } # else @@ -3375,7 +3292,7 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, int fd, struct ifreq *ifr) { - struct ethtool_gfeatures *g_cmd; + VIR_AUTOFREE(struct ethtool_gfeatures *) g_cmd =3D NULL; =20 if (VIR_ALLOC_VAR(g_cmd, struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) @@ -3385,7 +3302,6 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, g_cmd->size =3D GFEATURES_SIZE; if (virNetDevGFeatureAvailable(fd, ifr, g_cmd)) ignore_value(virBitmapSetBit(bitmap, VIR_NET_DEV_FEAT_TXUDPTNL)); - VIR_FREE(g_cmd); return 0; } # else --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806870687961.9591153314936; Sat, 28 Jul 2018 12:41:10 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id AAB1A30820DD; Sat, 28 Jul 2018 19:41:08 +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 5C0E56596C; Sat, 28 Jul 2018 19:41:07 +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 154104A465; Sat, 28 Jul 2018 19:41:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJeplC020427 for ; Sat, 28 Jul 2018 15:40:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 100903001A51; Sat, 28 Jul 2018 19:40:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 081563083320 for ; Sat, 28 Jul 2018 19:40:49 +0000 (UTC) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 E87708553D for ; Sat, 28 Jul 2018 19:40:47 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id n7-v6so5080502pgq.4 for ; Sat, 28 Jul 2018 12:40:47 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:46 -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=F1zLvnffDga0+Jf6JheyciGJ76QwMN+gKGx3WpMVhXU=; b=Ud1VQhuC9veXnfmxOHoliF/AH862GUg5zXJR5ap/HbrNWN8rjtdzsKfVeKJsm6+mPf OYhL4ZtgkeSzz7rPvPCkhRkp/cyWt1vSSHbRv9OctgW+Q6Xbz9AWmz9L2uX9aYU3Io4U OISU6AY53FRAnN0CaEAqqtybvvGdvwJ3VavvX1EcR4d00CBluDHKDyOfmm07E7rYjL6C 6oPbYdta6e7zwnQVeHoB+EV/Zczk3mBmvK3qbx6hqJhMAWaebmySaLgfwc2Jhdgu7ft7 23W7WfDhZFUI4GhlozAp3XWbbqhXTEQ6Aefc/ze2S6wO+ZfKkxqPbdj/L60kNaeurxw5 k9Hg== 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=F1zLvnffDga0+Jf6JheyciGJ76QwMN+gKGx3WpMVhXU=; b=oplyf738QjJwtcfDfZB3OpTamHwJA1Cfr5CvpBPtZaULnF930hYlk4IJuJD0gcauWn YzovNLurYIXczPwAYFkUm519ogF0aB4J71NWpLGkWx+ORGKg/qHjp+m8H1cGll8BYfLb x59yUaQNKDLLmkianbotyc7xbEdm/ifQPPclKIWPfe5ALP9dAMwy5VyPyKRIZdmCT/BI 8Md0cJdQAKDgaaVLnGCOmmD8yI08/IhiS5xFLoF0Mi+8Qvylaxz0s/odQ5kLdC+Ix6Xq PXod2gEEmIdl/gNn3+Juw+ypaHaBuf70wndMqmnmdVT3NlryrLWdOpEAfyDoKSjAN7XO qVpw== X-Gm-Message-State: AOUpUlHFQTf5B7om2YUZZ9/kJNBhmGpYyUcZ6KIK6gnKI5URYv/XURUe cYWOGNiGEFrZ0lCx5i8KEaBBoEMB X-Google-Smtp-Source: AAOMgpceWmEa72UJYOsYxxeYbKpLeXjRIYW6nyN52TTUDdaSIuygF2DVdvux9XAZwyFF1Wd46cBKMg== X-Received: by 2002:a63:3686:: with SMTP id d128-v6mr10470408pga.18.1532806847198; Sat, 28 Jul 2018 12:40:47 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:22 +0530 Message-Id: <1532800907-29115-8-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.28]); Sat, 28 Jul 2018 19:40:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 28 Jul 2018 19:40:48 +0000 (UTC) for IP:'209.85.215.182' DOMAIN:'mail-pg1-f182.google.com' HELO:'mail-pg1-f182.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.182 mail-pg1-f182.google.com 209.85.215.182 mail-pg1-f182.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 07/32] util: netdev: use VIR_AUTOPTR for aggregate 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:41:09 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdev.c | 129 ++++++++++++++++++++++-------------------------= ---- 1 file changed, 55 insertions(+), 74 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 7653f8b..c5871b4 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1855,16 +1855,15 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, const char *stateDir, bool saveVlan) { - int ret =3D -1; const char *pfDevName =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; VIR_AUTOFREE(char *) fileStr =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - virJSONValuePtr configJSON =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -1872,7 +1871,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; saveVlan =3D true; @@ -1884,12 +1883,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 if (pfDevName) { @@ -1907,7 +1906,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, * explicitly enable the PF in the host system network config. */ if (virNetDevGetOnline(pfDevName, &pfIsOnline) < 0) - goto cleanup; + return -1; =20 if (!pfIsOnline) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1916,12 +1915,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, "change host network config to put the " "PF online."), vf, pfDevName); - goto cleanup; + return -1; } } =20 if (!(configJSON =3D virJSONValueNewObject())) - goto cleanup; + return -1; =20 /* if there is a PF, it's now in pfDevName, and linkdev is either * the VF's name, or NULL (if the VF isn't bound to a net driver @@ -1930,11 +1929,11 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 if (pfDevName && saveVlan) { if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) = < 0) - goto cleanup; + return -1; =20 /* get admin MAC and vlan tag */ if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0) - goto cleanup; + return -1; =20 if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_ADMIN_MAC, @@ -1942,39 +1941,36 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, virJSONValueObjectAppendNumberInt(configJSON, VIR_NETDEV_KEYNAME_VLAN_TAG, oldVlanTag) < 0) { - goto cleanup; + return -1; } =20 } else { if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0) - goto cleanup; + return -1; } =20 if (linkdev) { if (virNetDevGetMAC(linkdev, &oldMAC) < 0) - goto cleanup; + return -1; =20 /* for interfaces with no pfDevName (i.e. not a VF, this will * be the only value in the file. */ if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_= MAC, virMacAddrFormat(&oldMAC, MACSt= r)) < 0) - goto cleanup; + return -1; } =20 if (!(fileStr =3D virJSONValueToString(configJSON, true))) - goto cleanup; + return -1; =20 if (virFileWriteStr(filePath, fileStr, O_CREAT|O_TRUNC|O_WRONLY) < 0) { virReportSystemError(errno, _("Unable to preserve mac/vlan tag " "for device =3D %s, vf =3D %d"), lin= kdev, vf); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virJSONValueFree(configJSON); - return ret; + return 0; } =20 =20 @@ -2012,7 +2008,10 @@ virNetDevReadNetConfig(const char *linkdev, int vf, VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; VIR_AUTOFREE(char *) fileStr =3D NULL; - virJSONValuePtr configJSON =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; + VIR_AUTOPTR(virMacAddr) tempAdminMAC =3D NULL; + VIR_AUTOPTR(virMacAddr) tempMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) tempVlan =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; @@ -2176,15 +2175,12 @@ virNetDevReadNetConfig(const char *linkdev, int vf, /* we won't need the file again */ ignore_value(unlink(filePath)); =20 - ret =3D 0; + return 0; cleanup: - if (ret < 0) { - VIR_FREE(*adminMAC); - VIR_FREE(*MAC); - VIR_FREE(*vlan); - } + VIR_STEAL_PTR(tempAdminMAC, *adminMAC); + VIR_STEAL_PTR(tempMAC, *MAC); + VIR_STEAL_PTR(tempVlan, *vlan); =20 - virJSONValueFree(configJSON); return ret; } =20 @@ -2214,13 +2210,12 @@ virNetDevSetNetConfig(const char *linkdev, int vf, const virMacAddr *MAC, bool setVlan) { - int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOPTR(virPCIDevice) vfPCIDevice =3D NULL; int vlanTag =3D -1; - virPCIDevicePtr vfPCIDevice =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2228,7 +2223,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; =20 @@ -2239,12 +2234,12 @@ virNetDevSetNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 =20 @@ -2256,14 +2251,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("admin MAC can only be set for SR-IOV VFs, bu= t " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 if (vlan) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("vlan can only be set for SR-IOV VFs, but " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 } else { @@ -2272,14 +2267,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("vlan trunking is not supported " "by SR-IOV network devices")); - goto cleanup; + return -1; } =20 if (!setVlan) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vlan tag set for interface %s but " "caller requested it not be set")); - goto cleanup; + return -1; } =20 vlanTag =3D vlan->tag[0]; @@ -2297,7 +2292,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, _("VF %d of PF '%s' is not bound to a net drive= r, " "so its MAC address cannot be set to %s"), vf, pfDevName, virMacAddrFormat(MAC, MACStr)); - goto cleanup; + return -1; } =20 setMACrc =3D virNetDevSetMACInternal(linkdev, MAC, !!pfDevOrig); @@ -2308,7 +2303,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, /* if pfDevOrig =3D=3D NULL, this isn't a VF, so we've failed = */ if (!pfDevOrig || (errno !=3D EADDRNOTAVAIL && errno !=3D EPERM)) - goto cleanup; + return -1; =20 /* Otherwise this is a VF, and virNetDevSetMAC failed with * EADDRNOTAVAIL/EPERM, which could be due to the @@ -2322,18 +2317,18 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 if (virNetDevSetVfConfig(pfDevName, vf, MAC, vlanTag, &allowRetry) < 0) { - goto cleanup; + return -1; } =20 /* admin MAC is set, now we need to construct a virPCIDevice * object so we can call virPCIDeviceRebind() */ if (!(vfPCIDevice =3D virNetDevGetPCIDevice(linkdev))) - goto cleanup; + return -1; =20 /* Rebind the device. This should set the proper MAC address */ if (virPCIDeviceRebind(vfPCIDevice) < 0) - goto cleanup; + return -1; =20 /* Wait until virNetDevGetIndex for the VF netdev returns succ= ess. * This indicates that the device is ready to be used. If we d= on't @@ -2385,20 +2380,17 @@ virNetDevSetNetConfig(const char *linkdev, int vf, * with the "locally administered" bit set. */ if (!allowRetry) - goto cleanup; + return -1; =20 allowRetry =3D false; if (virNetDevSetVfConfig(pfDevName, vf, &altZeroMAC, vlanTag, &allowRetry) < = 0) { - goto cleanup; + return -1; } } } =20 - ret =3D 0; - cleanup: - virPCIDeviceFree(vfPCIDevice); - return ret; + return 0; } =20 =20 @@ -2873,30 +2865,31 @@ virNetDevRxFilterFree(virNetDevRxFilterPtr filter) int virNetDevGetRxFilter(const char *ifname, virNetDevRxFilterPtr *filter) { - int ret =3D -1; bool receive =3D false; - virNetDevRxFilterPtr fil =3D virNetDevRxFilterNew(); + VIR_AUTOPTR(virNetDevRxFilter) fil =3D virNetDevRxFilterNew(); + + *filter =3D NULL; =20 if (!fil) - goto cleanup; + return -1; =20 if (virNetDevGetMAC(ifname, &fil->mac)) - goto cleanup; + return -1; =20 if (virNetDevGetMulticastTable(ifname, fil)) - goto cleanup; + return -1; =20 if (virNetDevGetPromiscuous(ifname, &fil->promiscuous)) - goto cleanup; + return -1; =20 if (virNetDevGetRcvAllMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) { fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_ALL; } else { if (virNetDevGetRcvMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NORMAL; @@ -2904,15 +2897,8 @@ int virNetDevGetRxFilter(const char *ifname, fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NONE; } =20 - ret =3D 0; - cleanup: - if (ret < 0) { - virNetDevRxFilterFree(fil); - fil =3D NULL; - } - - *filter =3D fil; - return ret; + VIR_STEAL_PTR(*filter, fil); + return 0; } =20 #if defined(SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ) @@ -3185,12 +3171,12 @@ virNetDevSwitchdevFeature(const char *ifname, { struct nl_msg *nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) pfname =3D NULL; + VIR_AUTOPTR(virPCIDevice) pci_device_ptr =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; - virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; - VIR_AUTOFREE(char *) pfname =3D NULL; int is_vf =3D -1; int ret =3D -1; uint32_t family_id; @@ -3251,7 +3237,6 @@ virNetDevSwitchdevFeature(const char *ifname, =20 cleanup: nlmsg_free(nl_msg); - virPCIDeviceFree(pci_device_ptr); return ret; } # else @@ -3507,8 +3492,7 @@ int virNetDevSetCoalesce(const char *ifname, int virNetDevRunEthernetScript(const char *ifname, const char *script) { - virCommandPtr cmd; - int ret; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Not a bug! Previously we did accept script=3D"" as a NO-OP. */ if (STREQ(script, "")) @@ -3522,8 +3506,5 @@ virNetDevRunEthernetScript(const char *ifname, const = char *script) #endif virCommandAddEnvPassCommon(cmd); =20 - ret =3D virCommandRun(cmd, NULL); - - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806879225750.7928785039442; Sat, 28 Jul 2018 12:41:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 168CF307D863; Sat, 28 Jul 2018 19:41:17 +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 D3CB8194AF; Sat, 28 Jul 2018 19:41:16 +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 87E173FB1D; Sat, 28 Jul 2018 19:41:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJereA020443 for ; Sat, 28 Jul 2018 15:40:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id CDAD45D6AA; Sat, 28 Jul 2018 19:40:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4EFE5D6A9 for ; Sat, 28 Jul 2018 19:40:50 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 8201530E684D for ; Sat, 28 Jul 2018 19:40:49 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id s7-v6so5075990pgv.3 for ; Sat, 28 Jul 2018 12:40:49 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:48 -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=DbYzgVg2eeR82I/eW6HMe50/tSyoUWh0J0rZzcz4Eaw=; b=IOS0QQX8gzMip0f4DByNURiCXVjVbad9fYqheMzUgJlcJduIXR6Ikj0H2cStFVLiM7 A5Hvnzwq2JLdA78gtfyck3aJ8bhhZz103fGexUbbNaEK/EppGiU7kr8fYiKBLcoIG6Ar EQZ39irIIYn/CRPozyAjuFMFxl8e6z7rCHQd/cYnZ8ZiYnt85VZrO/rqKzrR/KlVIh3C oIjVBH9DMYKv50zC85MKUoYz8Y39uqfJhcP+S/XtVcYL5Kg3FD1lyYfCXOhPN0JFEpJD OOHDhmN9EZ5BNb09W5qsBUWvobofTfzpKM/y4h3Snys82Hk3YKt1aiG1NNomUWUjEFDK Y5cw== 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=DbYzgVg2eeR82I/eW6HMe50/tSyoUWh0J0rZzcz4Eaw=; b=p4hxIGqpeBZLf9H9SXUJGcJGaqCJV/3Ev06x9idJOeZAuIwYI9Q0Kk2ACu+boq38d8 iXlWXHMeOIdPB3ZsL4GG+4G5XcREYDCFbPsOM5et9GXDSEqDdvfbuoxu7tym1Z6OUp4e o8+VHCtfkb57k3KgS9tV+fY8etYwswAuIjOqiMsoJHmZYuucTL1toa+wOzsAyfctT7Ko yXPUZD0+Rn92MHOHlsaxr8IKgMBGmyJedlgrxm6SagKL97laAHVAVTVtFuF8Cw3vf+7n 1ArGBQWw0z558V8f4uXzWUijaEpWXAvnMPEVOwZ40IyBWKa2Mbd6EVBk+ExRaKnluvoN sYrA== X-Gm-Message-State: AOUpUlHIfZNYpVPsFYdoyBwTN07HwQ9PvZoGWSeVFM7LNJDh8LdWssw/ Zz0yjA3ccdmL6n4m1AQFRo53/A86 X-Google-Smtp-Source: AAOMgpeijiPhyv+Ir5oNDTY1MsbB+Cw5Bv22Ios3iwism8tcoyx1+iQU4gvswsdWE1TpHwWsIXpmjg== X-Received: by 2002:a63:ad07:: with SMTP id g7-v6mr10577749pgf.19.1532806848807; Sat, 28 Jul 2018 12:40:48 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:23 +0530 Message-Id: <1532800907-29115-9-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.46]); Sat, 28 Jul 2018 19:40:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:40:49 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 08/32] util: socketaddr: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virSocketAddrPtr is declared using VIR_AUTOPTR, the function virSocketAddrFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virsocketaddr.c | 7 ++++++- src/util/virsocketaddr.h | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 5c3bfad..6b52a3d 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -26,7 +26,6 @@ #include "virsocketaddr.h" #include "virerror.h" #include "virstring.h" -#include "viralloc.h" #include "virbuffer.h" =20 #include @@ -1253,3 +1252,9 @@ virSocketAddrPTRDomain(const virSocketAddr *addr, ret =3D -2; goto cleanup; } + +void +virSocketAddrFree(virSocketAddrPtr addr) +{ + VIR_FREE(addr); +} diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 3029338..66f5998 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -24,14 +24,15 @@ #ifndef __VIR_SOCKETADDR_H__ # define __VIR_SOCKETADDR_H__ =20 -# include "internal.h" - # include # include # ifdef HAVE_SYS_UN_H # include # endif =20 +# include "internal.h" +# include "viralloc.h" + /* On architectures which lack these limits, define them (ie. Cygwin). * Note that the libvirt code should be robust enough to handle the * case where actual value is longer than these limits (eg. by setting @@ -162,4 +163,8 @@ int virSocketAddrPTRDomain(const virSocketAddr *addr, char **ptr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 +void virSocketAddrFree(virSocketAddrPtr addr); + +VIR_DEFINE_AUTOPTR_FUNC(virSocketAddr, virSocketAddrFree) + #endif /* __VIR_SOCKETADDR_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806874232991.0367646935016; Sat, 28 Jul 2018 12:41:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5347F5F72F; Sat, 28 Jul 2018 19:41:12 +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 1800B308BDAB; Sat, 28 Jul 2018 19:41:12 +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 ABB6918037F0; Sat, 28 Jul 2018 19:41:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJetnZ020455 for ; Sat, 28 Jul 2018 15:40:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id B06EDC64D5; Sat, 28 Jul 2018 19:40:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7B94CFBF7 for ; Sat, 28 Jul 2018 19:40:52 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (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 B2C854E907 for ; Sat, 28 Jul 2018 19:40:51 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id w3-v6so3733028plq.2 for ; Sat, 28 Jul 2018 12:40:51 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:50 -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=rfMPq0ziF0quKYbZHdYh8qPhZdC3GacXSalPXDT6Axc=; b=l4id2cdRjlwPNcVgLkQ43f+wnB6XhRiHS9AkHT2rk+KzjtFsAOzB/ATixqEDw4OSp3 2ytQ9QAz2ZvF352kIKwBXTvSzDFgSL2NXdyzDclwyQ8BeL1ubaGyyiwOVTdF6b+GXP6U PRPJC4byNKr4PUWAYyhgK1LIpwdf560ERoAmvjL5RMtDOk9uwfY+JhlwbYfryNIgBaRi 0P7ukPYPWm8NOPuqf3OXa26cK4dFega3laaYfQzjspu1ddeIWO8XLFP1HV/NGvFXa08s 9xRmqpY5es2ov2vgb6egP1JZpCIx9hQiXZt8WzuWRirXxUuXhTEdgJbXBpfHWWLQpjSO qRAg== 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=rfMPq0ziF0quKYbZHdYh8qPhZdC3GacXSalPXDT6Axc=; b=jz1Q6MC0rqhKepQ4v151Zk/YJKFdgg5q/8Vp3lowDbw7w7ewZ3UJ7if+9PvMTiL1j7 h3DLV0juP6ff0oogL57UwO8N4QLWnAi1Wkmngck5+I2acnyzeHy5xov2BK08y2A5Xa4S q5PHmid6ozZzASrCjXXcFYI/Sl+lieloTHiEjJvVDB5L5QsKrtxQS2PpAMknmmBNnjMB Dbj6la6VeBsnkVMoTpDueK7pLzrJuPlrRTjgaA+z2AAiRPdtv6GhqA+Q7kA8PtH/37DB WumBMFgaYUI8H+kPUHupoPs/UEuZ7bQftDf62gje35w3T59lU3JAt5bKCOsxLjVfhn4c 6/Ew== X-Gm-Message-State: AOUpUlHwSL6/NQET0ojq+vlEAv/wNAxd6Qf9zO0as7BfqGuD5pH2XC+x Tlw+PO9y7lQVnFPa1G/UY2i07wed X-Google-Smtp-Source: AAOMgpe4ZygIRhFiZU7fLFzRFENAG6ZZ3ldUKZp/cDH7/QFRC4aNcoL4OAI9h+nXV+wA06zYIcwq6A== X-Received: by 2002:a17:902:143:: with SMTP id 61-v6mr10569215plb.171.1532806850927; Sat, 28 Jul 2018 12:40:50 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:24 +0530 Message-Id: <1532800907-29115-10-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.38]); Sat, 28 Jul 2018 19:40:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 28 Jul 2018 19:40:51 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 09/32] util: socketaddr: 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 28 Jul 2018 19:41:13 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virsocketaddr.c | 70 ++++++++++++++++++++------------------------= ---- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 6b52a3d..eee725d 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -432,10 +432,10 @@ virSocketAddrFormatFull(const virSocketAddr *addr, if (withService) { if (virAsprintf(&addrstr, VIR_LOOPBACK_IPV4_ADDR"%s0", separator ? separator : ":") < 0) - goto error; + return NULL; } else { if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0) - goto error; + return NULL; } return addrstr; } @@ -452,33 +452,27 @@ virSocketAddrFormatFull(const virSocketAddr *addr, } =20 if (withService) { - char *ipv6_host =3D NULL; + VIR_AUTOFREE(char *) ipv6_host =3D NULL; /* sasl_new_client demands the socket address to be in an odd form= at: * a.b.c.d;port or e:f:g:h:i:j:k:l;port, so use square brackets for * IPv6 only if no separator is passed to the function */ if (!separator && VIR_SOCKET_ADDR_FAMILY(addr) =3D=3D AF_INET6) { if (virAsprintf(&ipv6_host, "[%s]", host) < 0) - goto error; + return NULL; } =20 if (virAsprintf(&addrstr, "%s%s%s", ipv6_host ? ipv6_host : host, separator ? separator : ":", port) =3D=3D -1) { - VIR_FREE(ipv6_host); - goto error; + return NULL; } - - VIR_FREE(ipv6_host); } else { if (VIR_STRDUP(addrstr, host) < 0) - goto error; + return NULL; } =20 return addrstr; - - error: - return NULL; } =20 =20 @@ -759,24 +753,26 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, int ret =3D 0; size_t i; virSocketAddr netmask; - char *startStr =3D NULL, *endStr =3D NULL, *netStr =3D NULL; + VIR_AUTOFREE(char *) startStr =3D NULL; + VIR_AUTOFREE(char *) endStr =3D NULL; + VIR_AUTOFREE(char *) netStr =3D NULL; =20 if (start =3D=3D NULL || end =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("NULL argument - %p %p"), start, end); - goto error; + return -1; } =20 startStr =3D virSocketAddrFormat(start); endStr =3D virSocketAddrFormat(end); if (!startStr || !endStr) - goto error; /*error already reported */ + return -1; /*error already reported */ =20 if (VIR_SOCKET_ADDR_FAMILY(start) !=3D VIR_SOCKET_ADDR_FAMILY(end)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("mismatch of address family in range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 if (network) { @@ -784,14 +780,14 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, * network the range should be within */ if (!(netStr =3D virSocketAddrFormat(network))) - goto error; + return -1; =20 if (VIR_SOCKET_ADDR_FAMILY(start) !=3D VIR_SOCKET_ADDR_FAMILY(netw= ork)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("mismatch of address family in " "range %s - %s for network %s"), startStr, endStr, netStr); - goto error; + return -1; } =20 if (prefix < 0 || @@ -801,7 +797,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("bad prefix %d for network %s when " " checking range %s - %s"), prefix, netStr, startStr, endStr); - goto error; + return -1; } =20 /* both start and end of range need to be within network */ @@ -811,7 +807,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("range %s - %s is not entirely within " "network %s/%d"), startStr, endStr, netStr, prefix); - goto error; + return -1; } =20 if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) { @@ -823,7 +819,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to construct broadcast or network= " "address for network %s/%d"), netStr, prefix); - goto error; + return -1; } =20 /* Don't allow the start of the range to be the network @@ -838,7 +834,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("start of range %s - %s in network %s/%d " "is the network address"), startStr, endStr, netStr, prefix); - goto error; + return -1; } =20 if (virSocketAddrEqual(end, &broadcast)) { @@ -846,7 +842,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("end of range %s - %s in network %s/%d " "is the broadcast address"), startStr, endStr, netStr, prefix); - goto error; + return -1; } } } @@ -860,7 +856,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to get IPv4 address " "for start or end of range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 /* legacy check that everything except the last two bytes @@ -868,10 +864,10 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, */ for (i =3D 0; i < 2; i++) { if (t1[i] !=3D t2[i]) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("range %s - %s is too large (> 65535)"), - startStr, endStr); - goto error; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("range %s - %s is too large (> 65535)"), + startStr, endStr); + return -1; } } ret =3D (t2[2] - t1[2]) * 256 + (t2[3] - t1[3]); @@ -879,7 +875,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s is reversed "), startStr, endStr); - goto error; + return -1; } ret++; } else if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET6)) { @@ -891,7 +887,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, _("failed to get IPv6 address " "for start or end of range %s - %s"), startStr, endStr); - goto error; + return -1; } =20 /* legacy check that everything except the last two bytes are @@ -902,7 +898,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s is too large (> 65535)"), startStr, endStr); - goto error; + return -1; } } ret =3D t2[7] - t1[7]; @@ -910,7 +906,7 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocket= AddrPtr end, virReportError(VIR_ERR_INTERNAL_ERROR, _("range %s - %s start larger than end"), startStr, endStr); - goto error; + return -1; } ret++; } else { @@ -918,18 +914,10 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSock= etAddrPtr end, _("unsupported address family " "for range %s - %s, must be ipv4 or ipv6"), startStr, endStr); - goto error; + return -1; } =20 - cleanup: - VIR_FREE(startStr); - VIR_FREE(endStr); - VIR_FREE(netStr); return ret; - - error: - ret =3D -1; - goto cleanup; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806883352511.6693539863618; Sat, 28 Jul 2018 12:41:23 -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 91BA6308213B; Sat, 28 Jul 2018 19:41:21 +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 543236016F; Sat, 28 Jul 2018 19:41:21 +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 00D5F180053A; Sat, 28 Jul 2018 19:41:20 +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 w6SJesfK020448 for ; Sat, 28 Jul 2018 15:40:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id B899D600C8; Sat, 28 Jul 2018 19:40:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0BBC600C5 for ; Sat, 28 Jul 2018 19:40:54 +0000 (UTC) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) (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 B6AE085A04 for ; Sat, 28 Jul 2018 19:40:53 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id 31-v6so3738760plc.4 for ; Sat, 28 Jul 2018 12:40:53 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:52 -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=6GC/yBHaInmLT67+NyBMzJ3/zne6Wtq/+Etry80lCgA=; b=BUBI7BcGu+jE5cfqGE2Z6aUkkA9wqlhWXLRfAKDtTpFEfKPcSoovFgQw3nHkpTvqZz DimQCN1PwGaz4gJkqBfuS5ueR54aHLEugYCNkWfGuAyXeFqR5YFX/srkeNsVk6OYT/xf LfEMZdG4Ic4y82OlOLBsjSA+OzG+FOKmW5pXxrdFYHAxKGqeOK/fWfVjcm5pgE05kyIv 4TxiOpIJsdGZW5k4Vr8cCVwzTS56oNvzikv8pL62JFc/ow3plTQmgMHA/oZeIfAJ6OWA e09WtuB3Xef+0MA1sAo6Yk3WqF3tIgeh2rN21AT8RuS8UVENUsl7vK/r73W7hsWeamAn gHew== 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=6GC/yBHaInmLT67+NyBMzJ3/zne6Wtq/+Etry80lCgA=; b=f7CaEalDuFwDcSjzuAWp+iYbPE1pgrWOh6YHeS4F6h0duoTL/MXBIzrSuWPSwg9Cqc B5MWaqsDAtTQVEnUrFtAqbd7Y6MO4f/giykdUfigX7Mox3z5hLomlRL6x8ZkU+1/9Zce SqIiTNiieFvJyMGEkuwcWVyKPvF5lZ3kLCHx5FwT44qB/lh/x/5DHuKJch7GGOEogGy1 fhQJnt3136dSnbAJUaPiKdvWS+6X/QEzT0pTgSek+9MU+R2RCg3G34IaiISrAD9OqU56 1Gef4LUIoFZzuXiLrDK8ls+rjqD9L2NZprQsWpNb1t9XYK6OR5LTkBCqYehzygYYI/Gs Pv6Q== X-Gm-Message-State: AOUpUlEKbajfxVJq/pNdDTuetK8RJqXiHLnU0Zm5b9lFZK9C1E7bPaHP 2S/Mbg5WQLtZdJw/bYk5TPP3/NxL X-Google-Smtp-Source: AAOMgpd6zwR9YCm+8+L4rzAT9IsgzIoi2cpQykbLrpRb3XV1tLiaBhUoI0dptzTADcaUX4Io7c9Xag== X-Received: by 2002:a17:902:e3:: with SMTP id a90-v6mr10897384pla.227.1532806853016; Sat, 28 Jul 2018 12:40:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:25 +0530 Message-Id: <1532800907-29115-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.26]); Sat, 28 Jul 2018 19:40:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 28 Jul 2018 19:40:53 +0000 (UTC) for IP:'209.85.160.53' DOMAIN:'mail-pl0-f53.google.com' HELO:'mail-pl0-f53.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.160.53 mail-pl0-f53.google.com 209.85.160.53 mail-pl0-f53.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/32] util: socketaddr: use VIR_AUTOPTR for aggregate 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.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.42]); Sat, 28 Jul 2018 19:41:22 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions 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/virsocketaddr.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index eee725d..1b195cd 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -1193,52 +1193,46 @@ virSocketAddrPTRDomain(const virSocketAddr *addr, unsigned int prefix, char **ptr) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOPTR(virBuffer) buf =3D NULL; size_t i; - int ret =3D -1; + + if (VIR_ALLOC(buf) < 0) + return -1; =20 if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) { virSocketAddrIPv4 ip; =20 if (prefix =3D=3D 0 || prefix >=3D 32 || prefix % 8 !=3D 0) - goto unsupported; + return -2; =20 if (virSocketAddrGetIPv4Addr(addr, &ip) < 0) - goto cleanup; + return -1; =20 for (i =3D prefix / 8; i > 0; i--) - virBufferAsprintf(&buf, "%u.", ip[i - 1]); + virBufferAsprintf(buf, "%u.", ip[i - 1]); =20 - virBufferAddLit(&buf, VIR_SOCKET_ADDR_IPV4_ARPA); + virBufferAddLit(buf, VIR_SOCKET_ADDR_IPV4_ARPA); } else if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) { virSocketAddrIPv6Nibbles ip; =20 if (prefix =3D=3D 0 || prefix >=3D 128 || prefix % 4 !=3D 0) - goto unsupported; + return -2; =20 if (virSocketAddrGetIPv6Nibbles(addr, &ip) < 0) - goto cleanup; + return -1; =20 for (i =3D prefix / 4; i > 0; i--) - virBufferAsprintf(&buf, "%x.", ip[i - 1]); + virBufferAsprintf(buf, "%x.", ip[i - 1]); =20 - virBufferAddLit(&buf, VIR_SOCKET_ADDR_IPV6_ARPA); + virBufferAddLit(buf, VIR_SOCKET_ADDR_IPV6_ARPA); } else { - goto unsupported; + return -2; } =20 - if (!(*ptr =3D virBufferContentAndReset(&buf))) - goto cleanup; + if (!(*ptr =3D virBufferContentAndReset(buf))) + return -1; =20 - ret =3D 0; - - cleanup: - virBufferFreeAndReset(&buf); - return ret; - - unsupported: - ret =3D -2; - goto cleanup; + return 0; } =20 void --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806889115398.88830318195323; Sat, 28 Jul 2018 12:41:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id ECE31308FBA2; Sat, 28 Jul 2018 19:41:26 +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 9C12C782D2; Sat, 28 Jul 2018 19:41:26 +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 2D51F3F67F; Sat, 28 Jul 2018 19:41:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJewQf020476 for ; Sat, 28 Jul 2018 15:40:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA0DB89DFA; Sat, 28 Jul 2018 19:40:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1BF645B4 for ; Sat, 28 Jul 2018 19:40:57 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (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 BCB8230820CA for ; Sat, 28 Jul 2018 19:40:55 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id n7-v6so5080583pgq.4 for ; Sat, 28 Jul 2018 12:40:55 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:54 -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=jo6IbHFgR2KEYmjFBw68raT6AiYgtkxVu7mZ91M6ODg=; b=tcLotwbJ4+tErIlc+QgMZQY+A+Bx/anXOJ7AsHbB2iuAqHx9ZXlmHB3i/l1aCHdwhh wpG8vFzsXpBXBUDQeYZOL0E5RtFRjW9zeTBukEytkMddt8nnYjswTjtm3msNZ75aFhcQ oF5435uzDbs77q1K1Y0vCGIVV74hwTsQ1vhOWsFrI5O897gJqm22ddWgd8h6J9phZJ96 CQ1bRUmjxEPiiEm9vY3sITQ1I+meS5ROlwTWZbbLPgMt54FX+WfwljHe5tFTjkpUIIDW gHTtqY94kz6Ft4cWSlhYQKoMw/msB0XmxOXvEMWmCqn2z01ZxKFpuDvxp4InhfOv/g9k wsJQ== 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=jo6IbHFgR2KEYmjFBw68raT6AiYgtkxVu7mZ91M6ODg=; b=FYZp/LYeDgmZknmRtYKrnTE7kocsFG7Ms3dNWB7UUjGgftoE/z06g9TKw1MJR2JAG/ kwiTu3VjxbVjnwhgXA3pZIrKnBNXgrdQ0umEe3l1MKjwTcpqaAzt5OU8EVgEmhhpqYzX ueQJ7dFIbhdCXN0D4Smo5tryRnNO4NJMfyhAmcnp+kg/H3+thNVflB89cZjrZrIu6nso WekICWubunhlvNHPLbs8Y4E8I8R1fPCIT81qzvSWJXDC7sf+US6+cj9Xf/5m/jY4d4NI 8aX0RR0ZRKA0aYHdbcbZ7lTLPQSAEPp+fbzAZpPlUGuha+GZBWepK56z69UtT8N7j51X j5sw== X-Gm-Message-State: AOUpUlFJJ9jVGAAJK0zHlfnd0dv8eZQ6V4eqmALSJfUmcOjXGPzjwiMt 4dzvw8yR7EF85B3Ml6+A69INj2uh X-Google-Smtp-Source: AAOMgpfjzjUEvP6sIuyZia4pbsXkWrBQgI1D5lft5Bd3WrQq2FB7Ciyq+JSmObJavT7pcJ66zNQxcA== X-Received: by 2002:a63:d20e:: with SMTP id a14-v6mr10653500pgg.226.1532806855061; Sat, 28 Jul 2018 12:40:55 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:26 +0530 Message-Id: <1532800907-29115-12-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.47]); Sat, 28 Jul 2018 19:40:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:40:55 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 11/32] util: netdevip: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 28 Jul 2018 19:41:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virNetDevIPAddrPtr and virNetDevIPRoutePtr are declared using VIR_AUTOPTR, the functions virNetDevIPAddrFree and virNetDevIPRouteFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevip.c | 7 ++++++- src/util/virnetdevip.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index bf98ed8..fdb0b74 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -27,7 +27,6 @@ #include "virnetlink.h" #include "virfile.h" #include "virerror.h" -#include "viralloc.h" #include "virlog.h" #include "virstring.h" #include "virutil.h" @@ -1129,3 +1128,9 @@ virNetDevIPInfoAddToDev(const char *ifname, cleanup: return ret; } + +void +virNetDevIPAddrFree(virNetDevIPAddrPtr ip) +{ + VIR_FREE(ip); +} diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h index 6b509ea..5608c37 100644 --- a/src/util/virnetdevip.h +++ b/src/util/virnetdevip.h @@ -84,6 +84,7 @@ int virNetDevIPAddrGet(const char *ifname, virSocketAddrP= tr addr) int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count) ATTRIBUTE_NONNULL(1); bool virNetDevIPCheckIPv6Forwarding(void); +void virNetDevIPAddrFree(virNetDevIPAddrPtr ip); =20 /* virNetDevIPRoute object */ void virNetDevIPRouteFree(virNetDevIPRoutePtr def); @@ -97,4 +98,7 @@ void virNetDevIPInfoClear(virNetDevIPInfoPtr ip); int virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPInfo const *ipInfo); =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPAddr, virNetDevIPAddrFree) +VIR_DEFINE_AUTOPTR_FUNC(virNetDevIPRoute, virNetDevIPRouteFree) + #endif /* __VIR_NETDEVIP_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806892807866.3555505075647; Sat, 28 Jul 2018 12:41:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E21B308214A; Sat, 28 Jul 2018 19:41:31 +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 D4FFF10512; Sat, 28 Jul 2018 19:41:30 +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 71D051800B69; Sat, 28 Jul 2018 19:41:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJf34b020510 for ; Sat, 28 Jul 2018 15:41:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id A492B60933; Sat, 28 Jul 2018 19:41:03 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B45E60930 for ; Sat, 28 Jul 2018 19:40:59 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 021AF369C8 for ; Sat, 28 Jul 2018 19:40:58 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id q7-v6so2880284pff.2 for ; Sat, 28 Jul 2018 12:40:57 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:56 -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=7I3xriz5+Ft/5IS4Sk7SV9s+jhuyBPt2s8L44uqqgfk=; b=BwpNGl+CwMnFD6jM+1IOmMbsaQGznpeL6l109jf0TSrIqygaePavtRojzfEpTw4bQF iAC56+i1w4DRSM6LMj8EQlOr/eeXUYGn3eHyu2Y9NlO2r1cCG+926Se9/swZg5s8C2OM PiVqKheGM0qLkDUlWQaOUW7FzHfl8XJgcUxF0ZCkvl0HHw1ZpVACmKQrOLW2a1Wp60Fz 60cyvY6S2kcoCroMelnxO/PvBaWczvIVyVAkY0OuOmyXqs4b5FfbdygX3qZD2pEtOTnn EVg5fm7HTd7xNtVkd3qs1nwFflmSCbcLsGW+vcvKzhpdciGengrymtO2ZVJsPw1tocbd 8hsw== 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=7I3xriz5+Ft/5IS4Sk7SV9s+jhuyBPt2s8L44uqqgfk=; b=lj0IHJ1xEzidSBAFzG7XTnqwec92SrZSK6SHoxD6eiwkrAN8UUwj7y8t/vd03X5A+V fD/OgPJYZrrDMLY7WG/dRNGolAdIJxZPnoBgreQmm2wnBe4/LR2tgk6fgBnZ5yGFJsPI 1e/ybBsGXQu1L6miGlo8CMDlKXXMR23js0MUGd6ZaZE/3AV6qtUiGEBTz20dUKXYjuld DHX89vj80ZeDN3/fhMqZj2CmclOGdJfXJKnwE6wtZmfujDM7ijEseIJIZ7ZJIzJVR53d ieKoJRIlbkolYxXDtF/1/7JOdBTkbW12ypOzHdteb5AWXxsNjV4cQoT7T+olvPc556sy PKyQ== X-Gm-Message-State: AOUpUlHce2Hbx+N+4pKARCSJ2JORBcErIgKpMJYZm8CWUUUwRCuST/pA 1bMvIhD6M3RaPWgTDQ1ZrB+oicmF X-Google-Smtp-Source: AAOMgpflb2xQ6a1VDKaQg36hUifkm7c9FI2tf1pMmKLU5XT4nNiamdvfORckwpNWv0dxzdLtwHlioA== X-Received: by 2002:a65:630e:: with SMTP id g14-v6mr10889178pgv.153.1532806857142; Sat, 28 Jul 2018 12:40:57 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:27 +0530 Message-Id: <1532800907-29115-13-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.30]); Sat, 28 Jul 2018 19:40:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 28 Jul 2018 19:40:58 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 12/32] util: netdevip: 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 28 Jul 2018 19:41:31 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 --- src/util/virnetdevip.c | 95 ++++++++++++++++++----------------------------= ---- 1 file changed, 33 insertions(+), 62 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index fdb0b74..8f1081b 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -171,11 +171,11 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *broadcast =3D NULL; int ret =3D -1; struct nl_msg *nlmsg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; - char *ipStr =3D NULL; - char *peerStr =3D NULL; - char *bcastStr =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) ipStr =3D NULL; + VIR_AUTOFREE(char *) peerStr =3D NULL; + VIR_AUTOFREE(char *) bcastStr =3D NULL; =20 ipStr =3D virSocketAddrFormat(addr); if (peer && VIR_SOCKET_ADDR_VALID(peer)) @@ -225,11 +225,7 @@ virNetDevIPAddrAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(ipStr); - VIR_FREE(peerStr); - VIR_FREE(bcastStr); nlmsg_free(nlmsg); - VIR_FREE(resp); VIR_FREE(broadcast); return ret; } @@ -252,7 +248,7 @@ virNetDevIPAddrDel(const char *ifname, { int ret =3D -1; struct nl_msg *nlmsg =3D NULL; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; unsigned int recvbuflen; =20 if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifna= me, @@ -273,7 +269,6 @@ virNetDevIPAddrDel(const char *ifname, ret =3D 0; cleanup: nlmsg_free(nlmsg); - VIR_FREE(resp); return ret; } =20 @@ -309,8 +304,8 @@ virNetDevIPRouteAdd(const char *ifname, int errCode; virSocketAddr defaultAddr; virSocketAddrPtr actualAddr; - char *toStr =3D NULL; - char *viaStr =3D NULL; + VIR_AUTOFREE(char *) toStr =3D NULL; + VIR_AUTOFREE(char *) viaStr =3D NULL; =20 actualAddr =3D addr; =20 @@ -383,8 +378,6 @@ virNetDevIPRouteAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(toStr); - VIR_FREE(viaStr); nlmsg_free(nlmsg); return ret; =20 @@ -452,7 +445,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) { struct nl_msg *nlmsg =3D NULL; struct ifaddrmsg ifa; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; int ret =3D -1; bool dad =3D true; @@ -475,6 +467,8 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) =20 /* Periodically query netlink until DAD finishes on all known addresse= s. */ while (dad && time(NULL) < max_time) { + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) goto cleanup; @@ -489,8 +483,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) dad =3D virNetDevIPParseDadStatus(resp, recvbuflen, addrs, count); if (dad) usleep(1000 * 10); - - VIR_FREE(resp); } /* Check timeout. */ if (dad) { @@ -502,7 +494,6 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) } =20 cleanup: - VIR_FREE(resp); nlmsg_free(nlmsg); return ret; } @@ -510,22 +501,18 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) static int virNetDevIPGetAcceptRA(const char *ifname) { - char *path =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *suffix; int accept_ra =3D -1; =20 if (virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra", ifname ? ifname : "all") < 0) - goto cleanup; + return -1; =20 if ((virFileReadAll(path, 512, &buf) < 0) || (virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0)) - goto cleanup; - - cleanup: - VIR_FREE(path); - VIR_FREE(buf); + return accept_ra; =20 return accept_ra; } @@ -545,9 +532,8 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlm= sghdr *resp, struct rtmsg *rtmsg =3D NLMSG_DATA(resp); int accept_ra =3D -1; struct rtattr *rta; - char *ifname =3D NULL; + VIR_AUTOFREE(char *) ifname =3D NULL; struct virNetDevIPCheckIPv6ForwardingData *data =3D opaque; - int ret =3D 0; int len =3D RTM_PAYLOAD(resp); int oif =3D -1; size_t i; @@ -555,7 +541,7 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlm= sghdr *resp, =20 /* Ignore messages other than route ones */ if (resp->nlmsg_type !=3D RTM_NEWROUTE) - return ret; + return 0; =20 /* Extract a device ID attribute */ VIR_WARNINGS_NO_CAST_ALIGN @@ -566,21 +552,20 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct n= lmsghdr *resp, =20 /* Should never happen: netlink message would be broken */ if (ifname) { - char *ifname2 =3D virNetDevGetName(oif); + VIR_AUTOFREE(char *) ifname2 =3D virNetDevGetName(oif); VIR_WARN("Single route has unexpected 2nd interface " "- '%s' and '%s'", ifname, ifname2); - VIR_FREE(ifname2); break; } =20 if (!(ifname =3D virNetDevGetName(oif))) - goto error; + return -1; } } =20 /* No need to do anything else for non RA routes */ if (rtmsg->rtm_protocol !=3D RTPROT_RA) - goto cleanup; + return 0; =20 data->hasRARoutes =3D true; =20 @@ -595,15 +580,9 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nl= msghdr *resp, } if (accept_ra !=3D 2 && !hasDevice && VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0) - goto error; + return -1; =20 - cleanup: - VIR_FREE(ifname); - return ret; - - error: - ret =3D -1; - goto cleanup; + return 0; } =20 bool @@ -687,7 +666,9 @@ virNetDevIPAddrAdd(const char *ifname, unsigned int prefix) { virCommandPtr cmd =3D NULL; - char *addrstr =3D NULL, *bcaststr =3D NULL, *peerstr =3D NULL; + VIR_AUTOFREE(char *) addrstr =3D NULL; + VIR_AUTOFREE(char *) bcaststr =3D NULL; + VIR_AUTOFREE(char *) peerstr =3D NULL; virSocketAddr broadcast; int ret =3D -1; =20 @@ -733,9 +714,6 @@ virNetDevIPAddrAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); - VIR_FREE(bcaststr); - VIR_FREE(peerstr); virCommandFree(cmd); return ret; } @@ -747,7 +725,7 @@ virNetDevIPAddrDel(const char *ifname, unsigned int prefix) { virCommandPtr cmd =3D NULL; - char *addrstr; + VIR_AUTOFREE(char *) addrstr =3D NULL; int ret =3D -1; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) @@ -773,7 +751,6 @@ virNetDevIPAddrDel(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); virCommandFree(cmd); return ret; } @@ -787,7 +764,8 @@ virNetDevIPRouteAdd(const char *ifname, unsigned int metric) { virCommandPtr cmd =3D NULL; - char *addrstr =3D NULL, *gatewaystr =3D NULL; + VIR_AUTOFREE(char *) addrstr =3D NULL; + VIR_AUTOFREE(char *) gatewaystr =3D NULL; int ret =3D -1; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) @@ -806,8 +784,6 @@ virNetDevIPRouteAdd(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(addrstr); - VIR_FREE(gatewaystr); virCommandFree(cmd); return ret; } @@ -1083,7 +1059,6 @@ int virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPInfo const *ipInfo) { - int ret =3D -1; size_t i; int prefix; =20 @@ -1093,16 +1068,15 @@ virNetDevIPInfoAddToDev(const char *ifname, =20 if ((prefix =3D virSocketAddrGetIPPrefix(&ip->address, NULL, ip->prefix)) < 0) { - char *ipStr =3D virSocketAddrFormat(&ip->address); + VIR_AUTOFREE(char *) ipStr =3D virSocketAddrFormat(&ip->addres= s); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to determine prefix for IP address '%= s'"), NULLSTR(ipStr)); - VIR_FREE(ipStr); - goto cleanup; + return -1; } if (virNetDevIPAddrAdd(ifname, &ip->address, &ip->peer, prefix) < = 0) - goto cleanup; + return -1; } =20 /* add all routes */ @@ -1110,23 +1084,20 @@ virNetDevIPInfoAddToDev(const char *ifname, virNetDevIPRoutePtr route =3D ipInfo->routes[i]; =20 if ((prefix =3D virNetDevIPRouteGetPrefix(route)) < 0) { - char *ipStr =3D virSocketAddrFormat(&route->address); + VIR_AUTOFREE(char *) ipStr =3D virSocketAddrFormat(&route->add= ress); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to determine prefix for route with de= stination '%s'"), NULLSTR(ipStr)); - VIR_FREE(ipStr); - goto cleanup; + return -1; } if (virNetDevIPRouteAdd(ifname, &route->address, prefix, &route->gateway, virNetDevIPRouteGetMetric(route)) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 void --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806864890629.2052084860769; Sat, 28 Jul 2018 12:41:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2ECB30E684D; Sat, 28 Jul 2018 19:41: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 98595C64D5; Sat, 28 Jul 2018 19:41: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 38E4818037F1; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJf1n6020491 for ; Sat, 28 Jul 2018 15:41:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2645ECFBF7; Sat, 28 Jul 2018 19:41:01 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EE87C64D5 for ; Sat, 28 Jul 2018 19:41:01 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 38D13308213B for ; Sat, 28 Jul 2018 19:41:00 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id r5-v6so5082393pgv.0 for ; Sat, 28 Jul 2018 12:41:00 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:59 -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=y/fvzVxgYczxcfc+Kz4aOAUDCuhnUtvGpo3G20qp+WY=; b=jAMxcyLoR8b4D4rl+BTyE4V/24Dyr4OiBDqcjHC52mtyqW8CUSGuRuy0whWECUNKd2 BY0dKYtS5L4VxQIlqtovJvsA0Bf0pGrcMY7cGAeq+lMrmSQczquyocYKKRoaC6et6MMm +l1IUyAXzEnN2e+HjbpVLAqFM9W/ZSaVy5etzhlx+t8QJTQytaVpvIB6H+OMjWJ5nAn6 h1DAluFogzqOhRDaP3Z1uIxXfm213GhWYxvJtS5PBVSqK67FWoia2tWvfKPNttFTUfBw ZCD/uYtmqXFPEJPSW90Sf488Ttbi5eDj2fxrTwY19DzHh2NonAEWHtqPomGNC0oTpIBB 5CJg== 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=y/fvzVxgYczxcfc+Kz4aOAUDCuhnUtvGpo3G20qp+WY=; b=ZKrt8XysmAwhVBp76oMeOTKhO9HsUQ6RPwBe1lM8ajeplYaLZ/FMQjtfrdavTXXJS5 CLDao8vYvh9J41mEFpkqYnXW11QsH2fVtg7Ml3RbLK0PHAUmGxPCosWv8veP4YOpFQ9A NPt+nI028oQKqowQhPVE0K8ThEF1QVvJVL9d4jEaDFV1ab9rDFxCa6utqY9a0+0XSAQR 0ZSjzuXIJdjH+KB2KkKdetoe5btlK8tbFT7UFZ3zCi3OnJfbX4Oy+DDhChNE54cEJjCF wFl8crSHUJiDHSxm9/rgctUmRyWQhWMOYLqbqwf2xe2xaEa5+BQ7mgiYXP1VOF/lBKCo nkIw== X-Gm-Message-State: AOUpUlELAGUXviSkX2TczP0ZeYYEsaCWp7LZ/RGcggZDAhHaFWOGW9Ey TH2kRYAPoOv/g57WeqUJWZYMbMrF X-Google-Smtp-Source: AAOMgpdFd4uC6L5Us2kIDdTmwlvMsOUJoLC5oG91oZEZ0HAjsXhKTPZ/TkYZzvg2zr8riF7mQqaMfQ== X-Received: by 2002:a62:990f:: with SMTP id d15-v6mr11716466pfe.162.1532806859487; Sat, 28 Jul 2018 12:40:59 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:28 +0530 Message-Id: <1532800907-29115-14-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.42]); Sat, 28 Jul 2018 19:41:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 28 Jul 2018 19:41:00 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 13/32] util: netdevip: use VIR_AUTOPTR for aggregate 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevip.c | 55 +++++++++++++++++++++-------------------------= ---- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 8f1081b..ca206e2 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -634,19 +634,22 @@ virNetDevIPCheckIPv6Forwarding(void) } =20 if (!valid) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOPTR(virBuffer) buf =3D NULL; + + if (VIR_ALLOC(buf) < 0) + goto cleanup; + for (i =3D 0; i < data.ndevices; i++) { - virBufferAdd(&buf, data.devices[i], -1); + virBufferAdd(buf, data.devices[i], -1); if (i < data.ndevices - 1) - virBufferAddLit(&buf, ", "); + virBufferAddLit(buf, ", "); } =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Check the host setup: enabling IPv6 forwarding w= ith " "RA routes without accept_ra set to 2 is likely t= o cause " "routes loss. Interfaces to look at: %s"), - virBufferCurrentContent(&buf)); - virBufferFreeAndReset(&buf); + virBufferCurrentContent(buf)); } =20 cleanup: @@ -665,24 +668,23 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *peer, unsigned int prefix) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) bcaststr =3D NULL; VIR_AUTOFREE(char *) peerstr =3D NULL; virSocketAddr broadcast; - int ret =3D -1; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; =20 if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr =3D virSocketAddr= Format(peer))) - goto cleanup; + return -1; =20 /* format up a broadcast address if this is IPv4 */ if (!peerstr && ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) && ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) || !(bcaststr =3D virSocketAddrFormat(&broadcast))))) { - goto cleanup; + return -1; } =20 # ifdef IFCONFIG_PATH @@ -710,12 +712,9 @@ virNetDevIPAddrAdd(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -724,12 +723,11 @@ virNetDevIPAddrDel(const char *ifname, virSocketAddr *addr, unsigned int prefix) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; - int ret =3D -1; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; # ifdef IFCONFIG_PATH cmd =3D virCommandNew(IFCONFIG_PATH); virCommandAddArg(cmd, ifname); @@ -747,12 +745,9 @@ virNetDevIPAddrDel(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -763,15 +758,14 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) gatewaystr =3D NULL; - int ret =3D -1; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; if (!(gatewaystr =3D virSocketAddrFormat(gateway))) - goto cleanup; + return -1; cmd =3D virCommandNew(IP_PATH); virCommandAddArgList(cmd, "route", "add", NULL); virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); @@ -780,12 +774,9 @@ virNetDevIPRouteAdd(const char *ifname, virCommandAddArgFormat(cmd, "%u", metric); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806869405930.6903881851043; Sat, 28 Jul 2018 12:41:09 -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 B429130E6850; Sat, 28 Jul 2018 19:41:07 +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 3E92960930; Sat, 28 Jul 2018 19:41:07 +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 D9D854BB78; Sat, 28 Jul 2018 19:41:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJf3Q1020505 for ; Sat, 28 Jul 2018 15:41:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D1A545B4; Sat, 28 Jul 2018 19:41:03 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0281989DFA for ; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 247143082A26 for ; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id y5-v6so5082724pgv.1 for ; Sat, 28 Jul 2018 12:41:02 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:01 -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=0yjDPX/1LjXTUbVaCDH2E8QU/WW55zgVnVxhxVAlGJA=; b=uBJYxrW9+RHtHp3WQaVfqE02XB5sab+V8Z0vTac9OEmBICDwXxELKCyK8wDNIUK7Cg j1aaxFwzlM8SajpIRnouRfRj2kQpAJisFfHWCGp4DKBZojoT9ZFj3lOuDRdP52+ZOwGO TxCXYUIeD77WuEeWBR5AeXibh49qG8cx2WdY9x+WC8P1gCZeHNv7jKiwF0zftF9AZcDA 6G3quKn6k1iXcYetjxAEILIqAlSMf8XV3V5mYHONP4v7ei6wtBBoLNJacpItqWbGUHsr fasGA1rm087wI1orQtaMbrdWys78IcxtaDYe4wzqJJY7bZ9iyUICIB3Il7qX8xzE1erU xIWw== 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=0yjDPX/1LjXTUbVaCDH2E8QU/WW55zgVnVxhxVAlGJA=; b=lrj4eeCtSFFkl5X8l2YM2m4U6Roc/km3c1uot8VBbyaBw4oyS1il4CXmiWPTP/qtP5 nzxsc/apcIIax8Tx8niiKG6yoD4CQK/GKQGSmAiSqTFzM0m4jZrq5NhPMVh2wcuWEbND 4jM5iATEx3K2SrX6+cmTcBnPWqLSeGo+Je/K2X0XWEHtvJxsCU8lCaDAvcYcHiwlLziO OyJL2vI7UNN0Nz48qidPSXnmlUwvcyUpu9hL11S8eMXb8+6dgYgKiQG+jW0Np8cNdBQJ dfVtktYkCR+1Un0guTI6CqaZ4GBx3t2aBNY+mKmp0WMahcoRb67IMRyKYoxjM/xvyLhJ dzzw== X-Gm-Message-State: AOUpUlEjlY79pLNFfBRb6CiILrX/BIw7vplG8UBm/bii+ieoXlpiwqcE J89/NCYn2eyw1tO2Z6llkx8BTmDW X-Google-Smtp-Source: AAOMgpdmMBn9jItW/qfyCoWOdWCVHJgOc9lzNx8xxF/o2qFq+FB9JeuqfsyfNnuveGvZGU0lHTn/rA== X-Received: by 2002:a62:a3d1:: with SMTP id q78-v6mr11629207pfl.5.1532806861445; Sat, 28 Jul 2018 12:41:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:29 +0530 Message-Id: <1532800907-29115-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.45]); Sat, 28 Jul 2018 19:41:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 28 Jul 2018 19:41:02 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 14/32] util: netdevmacvlan: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.46]); Sat, 28 Jul 2018 19:41:08 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virNetlinkCallbackDataPtr is declared using VIR_AUTOPTR, the function virNetlinkCallbackDataFree will be run automatically on it when it goes out of scope. This commit also adds an intermediate typedef for virNetlinkCallbackData type for use with the cleanup macros. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevmacvlan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index fb41bf9..91c6244 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -576,7 +576,7 @@ static const uint32_t modeMap[VIR_NETDEV_MACVLAN_MODE_L= AST] =3D { }; =20 /* Struct to hold the state and configuration of a 802.1qbg port */ -struct virNetlinkCallbackData { +struct _virNetlinkCallbackData { char *cr_ifname; virNetDevVPortProfilePtr virtPortProfile; virMacAddr macaddress; @@ -587,7 +587,8 @@ struct virNetlinkCallbackData { unsigned int linkState; }; =20 -typedef struct virNetlinkCallbackData *virNetlinkCallbackDataPtr; +typedef struct _virNetlinkCallbackData virNetlinkCallbackData; +typedef virNetlinkCallbackData *virNetlinkCallbackDataPtr; =20 # define INSTANCE_STRLEN 36 =20 @@ -870,6 +871,8 @@ virNetlinkCallbackDataFree(virNetlinkCallbackDataPtr ca= lld) VIR_FREE(calld); } =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetlinkCallbackData, virNetlinkCallbackDataFree) + /** * virNetDevMacVLanVPortProfileDestroyCallback: * --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806875168844.1105323345896; Sat, 28 Jul 2018 12:41:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7B8430820DC; Sat, 28 Jul 2018 19:41:12 +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 96D5A101F979; Sat, 28 Jul 2018 19:41:12 +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 2B45B18037FB; Sat, 28 Jul 2018 19:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJf71V020525 for ; Sat, 28 Jul 2018 15:41:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3700875548; Sat, 28 Jul 2018 19:41:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E4E7782CC for ; Sat, 28 Jul 2018 19:41:04 +0000 (UTC) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.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 0B8E2307D84A for ; Sat, 28 Jul 2018 19:41:04 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id l9-v6so2878717pff.9 for ; Sat, 28 Jul 2018 12:41:04 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:02 -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=M58oQEgUwHUvzR8Dcu0Z2Aksy9s1ULaPtRd/GfbaAFg=; b=eebmI4SrfzfYYrTu/nx285EqnYL8I1PAnAdYUGqo091z1g2OsFapKOuW8ygt0lDs6E 8nboNZVOi2riDJPEYNlKL2+0I4Aww3fuH35xRt0wl9WE0qMzmSB8I/kP7jOkqHxkuUa2 eTl4H4GsugX8bTNletU24POEDbhcp4YjhhxeG8Umwq6dlEOAsPR3plBJIHCclJePk/b4 pAAr1L7tl/WaogkXL2PelkNj4m3MFKyQDJ1Rbpxp1uu6idwKSP0mGPXHLlGtKZxAMGzv sXtD7CVzKMWjHnz3hQ35ZgJEiZ7bm+d77y5VdLa/y2ePK3DuPF9A7fMNuXAEi74CxHBX Jz3g== 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=M58oQEgUwHUvzR8Dcu0Z2Aksy9s1ULaPtRd/GfbaAFg=; b=F69uKf//NMGc5qG/DSAbPEKlKzPFBjXQffdH/eZF6n+1JiejOOZqlmttwu5gf2DDx2 /EnmdKxVF1qjpUOK5Nt3lSnByxrmSR9mHIZhrhIhREM/1E9YCxXuqq1wR9GuaHhWRSNb FA/ZUXHYLXXuvwhZN+TQWwZnK75Ot3YT5zBGAh7HXxOv6W0HTdOLSWCyFvt7OrpLT1hi ZttmlAcn+L7p7pXnUdz+2gPISoc5deRvI0T6p1j6/GMVPslPx462rj1csG7kCtsCg9lT BjD+5DbSWXSfBb5FwaARENRtuS/gQguJ2JO53xhexkny4GZlIkBlk48uTDUGEqWYxgv4 umYw== X-Gm-Message-State: AOUpUlFYbwMIWmejITczl3p0/3zT+c1Yxk4/fNq2Okc96rrfGClO30lb P5im7wWDGCTY5xGpolI3rKztjjP9 X-Google-Smtp-Source: AAOMgpcW/pvahR5bhPWjAP28NJtfgSNjsqsd3D4kd/M2cwDDBX0/uql6X4lVFiXCbCrBm7Adsq8LBg== X-Received: by 2002:a62:3001:: with SMTP id w1-v6mr11710539pfw.19.1532806863272; Sat, 28 Jul 2018 12:41:03 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:30 +0530 Message-Id: <1532800907-29115-16-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.48]); Sat, 28 Jul 2018 19:41:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:04 +0000 (UTC) for IP:'209.85.210.171' DOMAIN:'mail-pf1-f171.google.com' HELO:'mail-pf1-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.210.171 mail-pf1-f171.google.com 209.85.210.171 mail-pf1-f171.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 15/32] util: netdevmacvlan: 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:41:13 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virnetdevmacvlan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 91c6244..a2ed65c 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -308,7 +308,7 @@ virNetDevMacVLanCreate(const char *ifname, int *retry) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; int ifindex; @@ -403,7 +403,6 @@ virNetDevMacVLanCreate(const char *ifname, rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -452,7 +451,7 @@ virNetDevMacVLanTapOpen(const char *ifname, { int ret =3D -1; int ifindex; - char *tapname =3D NULL; + VIR_AUTOFREE(char *) tapname =3D NULL; size_t i =3D 0; =20 if (virNetDevGetIndex(ifname, &ifindex) < 0) @@ -487,7 +486,6 @@ virNetDevMacVLanTapOpen(const char *ifname, while (i--) VIR_FORCE_CLOSE(tapfd[i]); } - VIR_FREE(tapname); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806879141130.42631729673144; Sat, 28 Jul 2018 12:41:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F6F0C0587C9; Sat, 28 Jul 2018 19:41:17 +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 B770C308BDB3; Sat, 28 Jul 2018 19:41:16 +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 6E1DF3FCC3; Sat, 28 Jul 2018 19:41:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJf8bH020533 for ; Sat, 28 Jul 2018 15:41:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A4E3CFBF7; Sat, 28 Jul 2018 19:41:08 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32782C64D5 for ; Sat, 28 Jul 2018 19:41:07 +0000 (UTC) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 403DE300175D for ; Sat, 28 Jul 2018 19:41:06 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id a26-v6so2883019pfo.4 for ; Sat, 28 Jul 2018 12:41:06 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:05 -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=DIlvjd577YULIxeszamBnLEZywKZdXziClQO6akbe0Y=; b=tnxwUlXGh6ogU7su8r7mBZ/C5EfniVm1hpyCClcBQ4nKsKNt437Y3iZ3GxjTiTndCa J65qlziaSzKi96I/nSk31v/zO9/iXuF1H8QCpL4HF5qmM4Y9Wh5y5YDwgrfI6OAtSalF dMUL6fvFN1rEjgwnxhGV8o5yblNrZ2sUGzKmxKX0U8tfIVjrzbwwSXZVQUSxJ5qT/xLW zDXU+0zK0rQGkvNfiufM+eGf9sdf42IsiS4Sj26GiGca4B5cokJJelYGxnInDuZAxn8j cWij9fd8ORmihMIYlGmiI08KmZJ9NVupIKAKkMCZy4E1D2Ka6uxf4F//1Wug+cBkfzfW MFuQ== 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=DIlvjd577YULIxeszamBnLEZywKZdXziClQO6akbe0Y=; b=ubPsL4QonOxVmIJg8wZx7Ld1jtCFH8NNw3Idt+ZqeTE5JJg82y+fPHMbdPNH/vhNwE AyPNVSOT1JKWCl4vQ4CXuzfjteeMfpzdq0Wnb9It0AH7xJ7ruDBE8BCIAKTP06kxTb7Q zf+ZhB48X7zyCYwK9VAbOkcynDZbV+C5vxawWAiWOCuazNz0LfRyGzfpNzdVR3pPPFCD 2SSxn6siJkBYFfvNuUffX3roDuT00Ipl6amVZWiJa7NqgOTDn4YEfpJSxOT3iNpJoS61 YvIhPegP6zX809MtwyS6SKHeiETz60ZrwYgxVMXz0bvYVq9vFqvzBQNBXRzuQpYvfrz1 p7BQ== X-Gm-Message-State: AOUpUlFuvkQY2ZFUabiHcV7pFO4DQMyI4pXVn8cVSEy+oPoid8Bfvi+k y5RHWZGqxQsgTKXG649yHyszd0xj X-Google-Smtp-Source: AAOMgpfNXtg9EdASewS+VSF7gz0gPJg8NP/iUrlafy+XsTzxxRS5V77Nd1/wA/eBCKF5ECEto5F4Mw== X-Received: by 2002:a62:2744:: with SMTP id n65-v6mr11768124pfn.125.1532806865514; Sat, 28 Jul 2018 12:41:05 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:31 +0530 Message-Id: <1532800907-29115-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.46]); Sat, 28 Jul 2018 19:41:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:06 +0000 (UTC) for IP:'209.85.210.180' DOMAIN:'mail-pf1-f180.google.com' HELO:'mail-pf1-f180.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.210.180 mail-pf1-f180.google.com 209.85.210.180 mail-pf1-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 16/32] util: netdevmacvlan: use VIR_AUTOPTR for aggregate 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 28 Jul 2018 19:41:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions 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/virnetdevmacvlan.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index a2ed65c..d01e5ef 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -898,19 +898,20 @@ virNetDevMacVLanVPortProfileRegisterCallback(const ch= ar *ifname, virNetDevVPortProfilePtr virt= PortProfile, virNetDevVPortProfileOp vmOp) { - virNetlinkCallbackDataPtr calld =3D NULL; + VIR_AUTOPTR(virNetlinkCallbackData) calld =3D NULL; + virNetlinkCallbackDataPtr temp ATTRIBUTE_UNUSED =3D NULL; =20 if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE))= { if (VIR_ALLOC(calld) < 0) - goto error; + return -1; if (VIR_STRDUP(calld->cr_ifname, ifname) < 0) - goto error; + return -1; if (VIR_ALLOC(calld->virtPortProfile) < 0) - goto error; + return -1; memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortPr= ofile)); virMacAddrSet(&calld->macaddress, macaddress); if (VIR_STRDUP(calld->linkdev, linkdev) < 0) - goto error; + return -1; memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid)); =20 calld->vmOp =3D vmOp; @@ -918,14 +919,12 @@ virNetDevMacVLanVPortProfileRegisterCallback(const ch= ar *ifname, if (virNetlinkEventAddClient(virNetDevMacVLanVPortProfileCallback, virNetDevMacVLanVPortProfileDestroyCa= llback, calld, macaddress, NETLINK_ROUTE) < 0) - goto error; + return -1; } =20 + VIR_STEAL_PTR(temp, calld); + return 0; - - error: - virNetlinkCallbackDataFree(calld); - return -1; } =20 =20 @@ -1184,9 +1183,9 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char= *ifname, } =20 if (mode =3D=3D VIR_NETDEV_MACVLAN_MODE_PASSTHRU) { - virMacAddrPtr MAC =3D NULL; - virMacAddrPtr adminMAC =3D NULL; - virNetDevVlanPtr vlan =3D NULL; + VIR_AUTOPTR(virMacAddr) MAC =3D NULL; + VIR_AUTOPTR(virMacAddr) adminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) vlan =3D NULL; =20 if ((virNetDevReadNetConfig(linkdev, -1, stateDir, &adminMAC, &vlan, &MAC) =3D=3D 0) && @@ -1194,9 +1193,6 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char= *ifname, =20 ignore_value(virNetDevSetNetConfig(linkdev, -1, adminMAC, vlan, MAC, !!vlan= )); - VIR_FREE(MAC); - VIR_FREE(adminMAC); - virNetDevVlanFree(vlan); } } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806887401983.0814777200949; Sat, 28 Jul 2018 12:41:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7F7B0C057FA2; Sat, 28 Jul 2018 19:41:25 +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 41AC367CFB; Sat, 28 Jul 2018 19:41:25 +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 CD69D1800CAC; Sat, 28 Jul 2018 19:41:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfDAv020552 for ; Sat, 28 Jul 2018 15:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1144C2010CE7; Sat, 28 Jul 2018 19:41:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07B412010CE6 for ; Sat, 28 Jul 2018 19:41:09 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 97318308213E for ; Sat, 28 Jul 2018 19:41:08 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id y4-v6so5071338pgp.9 for ; Sat, 28 Jul 2018 12:41:08 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41: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=+ZT/6bAn+j5p+6JZOraUQVZ7i0BiLWbB9/FFEnhltCM=; b=uOFeZnVW3to1Q5hkeDSunTWRKXnQXLLuG6z5vnkZ91qBcLgM/W3pMaTOm2hSUc4GW8 L0gjz8PFeKIijIW2ZWlv6HuBurAeFc1ej9CJJjOjypTTab1QB32PF0pBJCPTPPTxG8Xr wzc+okkVB+TekFcT1KZXXJyF3eMb2ojMMyK+8plwXewvgYib+rW4G61AZylTThBagRsw rScJIuMqYHWEeRVWyomgRlaO35KVfmo/6wqz4iSl5wUMli4PVbCjDTiQq734qvMDJ6pn VJh5W7f76wUouv4DDUYrt1KYBfwvByXhc0RH83IkPzwes0gFzIqUWI7Ue6eWAiNsOgzP TTNQ== 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=+ZT/6bAn+j5p+6JZOraUQVZ7i0BiLWbB9/FFEnhltCM=; b=rVTuw9Q2pFBTNd4X0x2K5suLWFk/J1FbVq/KPmfv/1blt6GxQlKc3z8RDETsdfZ0Ko 29xTtK6rGdLim8ra5vwJb6YTV58OmwDZcpUSOAq6JzJlP9wibvnUnHmoYEkJJgry2oa6 o67btt+P4Dj4ga+ofnyS7f7cNiwfp2LB/bP30ojthay9IlsY7CkR5VMMoxNdOO+/CoG4 TTz5Jzgrw/qDMJDuiBAKwcviWaEEe9lLj/JpIsST1kdmjUfmlXmABJTuKLg0/9zCP/hi A3ju1UTK2aRFpVkz6g+N6aOHDdhiyAHpu4UgsnK8RLYGSFNKZ8Mftw4I/X0g0EoHb4Et 0Hsg== X-Gm-Message-State: AOUpUlFq3sIh6NJoJ6dKi2bHNcRu40siYZjQOJSDIsw5Oh4BQV2tTp9h kgEKcueS/K4ijWpam9pjqql/l+ZT X-Google-Smtp-Source: AAOMgped1ms22X70VBqVXKjE93mqmMmYSnXUKIQuvTk5xbUt16zsJuP1V1u6E872Ym9VXPqldHXm8g== X-Received: by 2002:a62:d646:: with SMTP id r67-v6mr11824315pfg.130.1532806867822; Sat, 28 Jul 2018 12:41:07 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:32 +0530 Message-Id: <1532800907-29115-18-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.42]); Sat, 28 Jul 2018 19:41:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 28 Jul 2018 19:41:08 +0000 (UTC) for IP:'209.85.215.180' DOMAIN:'mail-pg1-f180.google.com' HELO:'mail-pg1-f180.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.180 mail-pg1-f180.google.com 209.85.215.180 mail-pg1-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 17/32] util: netdevopenvswitch: 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 28 Jul 2018 19:41:26 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 --- src/util/virnetdevopenvswitch.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index d1c5cf4..a9c5e2a 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -149,10 +149,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; - char *attachedmac_ex_id =3D NULL; - char *ifaceid_ex_id =3D NULL; - char *profile_ex_id =3D NULL; - char *vmid_ex_id =3D NULL; + VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; + VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; + VIR_AUTOFREE(char *) profile_ex_id =3D NULL; + VIR_AUTOFREE(char *) vmid_ex_id =3D NULL; =20 virMacAddrFormat(macaddr, macaddrstr); virUUIDFormat(ovsport->interfaceID, ifuuidstr); @@ -209,10 +209,6 @@ int virNetDevOpenvswitchAddPort(const char *brname, co= nst char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(attachedmac_ex_id); - VIR_FREE(ifaceid_ex_id); - VIR_FREE(vmid_ex_id); - VIR_FREE(profile_ex_id); virCommandFree(cmd); return ret; } @@ -339,7 +335,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { virCommandPtr cmd =3D NULL; - char *output; + VIR_AUTOFREE(char *) output =3D NULL; char *tmp; bool gotStats =3D false; int ret =3D -1; @@ -399,7 +395,6 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, ret =3D 0; =20 cleanup: - VIR_FREE(output); virCommandFree(cmd); return ret; } @@ -424,7 +419,6 @@ int virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master) { virCommandPtr cmd =3D NULL; - int ret =3D -1; int exitstatus; =20 *master =3D NULL; @@ -438,7 +432,7 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifna= me, char **master) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS master for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 /* non-0 exit code just means that the interface has no master in OVS = */ @@ -454,9 +448,7 @@ virNetDevOpenvswitchInterfaceGetMaster(const char *ifna= me, char **master) =20 VIR_DEBUG("OVS master for %s is %s", ifname, *master ? *master : "(non= e)"); =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -476,12 +468,12 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *pa= th, char **ifname) { virCommandPtr cmd =3D NULL; + VIR_AUTOFREE(char *) ovs_timeout =3D NULL; char *tmpIfname =3D NULL; char **tokens =3D NULL; size_t ntokens =3D 0; int status; int ret =3D -1; - char *ovs_timeout =3D NULL; =20 /* Openvswitch vhostuser path are hardcoded to * //openvswitch/ @@ -513,7 +505,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, cleanup: virStringListFreeCount(tokens, ntokens); virCommandFree(cmd); - VIR_FREE(ovs_timeout); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 15328068829221000.1183945860439; Sat, 28 Jul 2018 12:41:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3051730820E6; Sat, 28 Jul 2018 19:41:21 +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 F00862010CEA; Sat, 28 Jul 2018 19:41:20 +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 9AAD23F7D2; Sat, 28 Jul 2018 19:41:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfDwX020553 for ; Sat, 28 Jul 2018 15:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13BE810512; Sat, 28 Jul 2018 19:41:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0922B89DFA for ; Sat, 28 Jul 2018 19:41:12 +0000 (UTC) Received: from mail-pl0-f42.google.com (mail-pl0-f42.google.com [209.85.160.42]) (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 2420230832E4 for ; Sat, 28 Jul 2018 19:41:11 +0000 (UTC) Received: by mail-pl0-f42.google.com with SMTP id f6-v6so3740055plo.1 for ; Sat, 28 Jul 2018 12:41:11 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:09 -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=TLRNwpicCHt0zoXGrO5LNqfLMhIfbkStpCEi1ZOV3rs=; b=b8yJsMR/sTd1lS4TkuNRasmjl1sdFYeY5KHHU6/ggvv6IPy1LdNXQ2NByMGPUI2cGy Lp7Za6J8wJn3xXI/3c/vbMN/NNdiyavIiXDTKwUW/H6a3Y+TN+n6B/GYZeg756D4dBvX t7Rapm8+Glo/bbOi6R0BvUwMqFcZc3Ypc5XmfN9OYC4nD4FbHvANvGju8NM2F7rp+vgK ofaPGtNV1lpH6U1HqAu63foQbHZsRA5VPvKrdVCTqEmLjDz/OBjMs6p4rs5emTtpcF07 K5ngvd0HODUGd5EtDwJfoe4AHhZ+egdwlKok2e1ur3GKxYnzhpBUgAov3TviaOC6hhlg G2wQ== 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=TLRNwpicCHt0zoXGrO5LNqfLMhIfbkStpCEi1ZOV3rs=; b=fHatVWcm/xBEVo0XF/WF2igte9mCo0R0Vq+PqJikjGesZLLHuXLqVFxrL1Qd/iKxeN MGP+j58TXF/q+A7UWyyBvIQAE66YjjoTO+eiVCPQ7hWCNIietBy0Hgvu5JHLPfSGSJTk Nhb50F3nGHEdYhTZ5fR3BCk9g1onB2KPfHCV2Kj4kkuC0UPszpclz7aO2m3MZ/s3pZOm ikNubhdt2s1DIVhhhKUBOxFw3C5dkdUhVvN0sM3R/W1m4IBhT41nLdmZchg9JhwI0val mbr/LpRlIFff+oMsaLgTg1CUMo7WnyH+8B6Tn/a/Pknjv5i7Nh0gZeoGfbNncsdv54Yt bw8Q== X-Gm-Message-State: AOUpUlH0I/G7N0OkAHO0PPZQByQJYihmPJNyVmrsZSZnezstIG2HZwpl pKLSwtToBvFI5RPG67Gmq3dC5gEd X-Google-Smtp-Source: AAOMgpe4cOyisRUhLjr9dNt/QV51feMcvisTU0MHuir7bcXD5DC18w88xUrtmpl1mgV3NHaQUCgmSQ== X-Received: by 2002:a17:902:b609:: with SMTP id b9-v6mr10644961pls.321.1532806870409; Sat, 28 Jul 2018 12:41:10 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:33 +0530 Message-Id: <1532800907-29115-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.44]); Sat, 28 Jul 2018 19:41:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:11 +0000 (UTC) for IP:'209.85.160.42' DOMAIN:'mail-pl0-f42.google.com' HELO:'mail-pl0-f42.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.160.42 mail-pl0-f42.google.com 209.85.160.42 mail-pl0-f42.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 18/32] util: netdevopenvswitch: use VIR_AUTOPTR for aggregate 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:41:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevopenvswitch.c | 106 +++++++++++++++---------------------= ---- 1 file changed, 40 insertions(+), 66 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index a9c5e2a..eae5861 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -76,9 +76,7 @@ virNetDevOpenvswitchAddTimeout(virCommandPtr cmd) static int virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, virNetDevVlanPtr vir= tVlan) { - int ret =3D -1; size_t i =3D 0; - virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 if (!virtVlan || !virtVlan->nTags) return 0; @@ -98,7 +96,12 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, vi= rNetDevVlanPtr virtVlan) } =20 if (virtVlan->trunk) { - virBufferAddLit(&buf, "trunk=3D"); + VIR_AUTOPTR(virBuffer) buf =3D NULL; + + if (VIR_ALLOC(buf) < 0) + return -1; + + virBufferAddLit(buf, "trunk=3D"); =20 /* * Trunk ports have at least one VLAN. Do the first one @@ -106,24 +109,21 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd,= virNetDevVlanPtr virtVlan) * start of the for loop if there are more than one VLANs * on this trunk port. */ - virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); =20 for (i =3D 1; i < virtVlan->nTags; i++) { - virBufferAddLit(&buf, ","); - virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); + virBufferAddLit(buf, ","); + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } =20 - if (virBufferCheckError(&buf) < 0) - goto cleanup; - virCommandAddArg(cmd, virBufferCurrentContent(&buf)); + if (virBufferCheckError(buf) < 0) + return -1; + virCommandAddArg(cmd, virBufferCurrentContent(buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=3D%d", virtVlan->tag[0]); } =20 - ret =3D 0; - cleanup: - virBufferFreeAndReset(&buf); - return ret; + return 0; } =20 /** @@ -144,11 +144,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virNetDevVPortProfilePtr ovsport, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; VIR_AUTOFREE(char *) profile_ex_id =3D NULL; @@ -160,17 +159,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, =20 if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=3D\"%s\= "", macaddrstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=3D\"%s\"", ifuuidstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=3D\"%s\"", vmuuidstr) < 0) - goto cleanup; + return -1; if (ovsport->profileID[0] !=3D '\0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=3D\"%s\= "", ovsport->profileID) < 0) - goto cleanup; + return -1; } =20 cmd =3D virCommandNew(OVSVSCTL); @@ -179,7 +178,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, ifname, "--", "add-port", brname, ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (ovsport->profileID[0] =3D=3D '\0') { virCommandAddArgList(cmd, @@ -204,13 +203,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to add port %s to OVS bridge %s"), ifname, brname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -223,8 +219,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, */ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, co= nst char *ifname) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -233,13 +228,10 @@ int virNetDevOpenvswitchRemovePort(const char *brname= ATTRIBUTE_UNUSED, const ch if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to delete port %s from OVS"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -253,9 +245,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname A= TTRIBUTE_UNUSED, const ch */ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; size_t len; - int ret =3D -1; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -269,7 +260,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 /* Wipeout the newline, if it exists */ @@ -277,10 +268,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate,= const char *ifname) if (len > 0) (*migrate)[len - 1] =3D '\0'; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -294,8 +282,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) */ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!migrate) { VIR_DEBUG("No OVS port data for interface %s", ifname); @@ -312,13 +299,10 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate,= const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to set OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -334,11 +318,10 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) output =3D NULL; char *tmp; bool gotStats =3D false; - int ret =3D -1; =20 /* Just ensure the interface exists in ovs */ cmd =3D virCommandNew(OVSVSCTL); @@ -350,7 +333,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, /* no ovs-vsctl or interface 'ifname' doesn't exists in ovs */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface not found")); - goto cleanup; + return -1; } =20 #define GET_STAT(name, member) \ @@ -369,7 +352,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, *tmp !=3D '\n') { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Fail to parse ovs-vsctl output")); \ - goto cleanup; \ + return -1; \ } \ gotStats =3D true; \ } \ @@ -389,14 +372,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, if (!gotStats) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface doesn't have any statistics")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -467,7 +446,7 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ovs_timeout =3D NULL; char *tmpIfname =3D NULL; char **tokens =3D NULL; @@ -504,7 +483,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, =20 cleanup: virStringListFreeCount(tokens, ntokens); - virCommandFree(cmd); return ret; } =20 @@ -520,8 +498,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, int virNetDevOpenvswitchUpdateVlan(const char *ifname, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -532,16 +509,13 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, "--", "--if-exists", "set", "Port", ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to set vlan configuration on port %s"), i= fname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806892322592.4273795011369; Sat, 28 Jul 2018 12:41:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B851A308625E; Sat, 28 Jul 2018 19:41:30 +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 78BA410694F0; Sat, 28 Jul 2018 19:41:30 +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 2816F264D3; Sat, 28 Jul 2018 19:41:30 +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 w6SJfILb020879 for ; Sat, 28 Jul 2018 15:41:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 43E3C67CFD; Sat, 28 Jul 2018 19:41:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3AE4867CFB for ; Sat, 28 Jul 2018 19:41:14 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (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 5A88512C27 for ; Sat, 28 Jul 2018 19:41:13 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id s17-v6so3735007plp.7 for ; Sat, 28 Jul 2018 12:41:13 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:12 -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=CWAM/Pnj526zqBP6hwY4MM+4AGzAF6RjIOdgite8aA8=; b=PRJql48wymF21+JZzE2avk5Sol4SOB5kESC3zhrUF97nlXp75HJcENqjFwxh/dsVv/ P5xdZnZHPFGFe9gjWWHWB936Hu2c1qauYiAgVQImGdCAlB/eAyeGAzo60RrYBaeymw94 g4+8Z/HBWLT8YfgPBpDDK/i6PyldYpEBwk02WooQUJrcVeOkpWfMw5FfXgE68xp2isDy zBEIGhFAGTWJxmf2j4YqI0uLXwIiVUR1K21GQ86tVoHf56QOX/WqOcuMnvM02FNKlBFq 6hbbgWWkw7gc9qoPMakPQQtwNkB2qd8tY6c1QatpotX3cDr45WdsOeGknjIHlvm6pzTR obJg== 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=CWAM/Pnj526zqBP6hwY4MM+4AGzAF6RjIOdgite8aA8=; b=V51dOcEF8W9PkjxCKIQbo7AcJ+16wzeWMwvDoouytcAKldLVwaqumVgYv3AWcDTbV8 ZKCKmB4t+Y3ioIeUvYf8rtv5lKNQy9VZHS76mwW3mLs1I46BqycsQM+yBR0c/23tsOHz VxRNTuJK5hAW27MsYL6BYCBuKq1BEt0meX/7LXdgIK45tUgAR8hBdls/hiShxUt0WMub V+IDaczLkyVhbk6pMMQQWc1FIvh4MSXqcRNoJZtIpQRb4Au+fK8i/Cxsw75CY7pM31Ui 4fx4YpILYxU2KTNE32b5G8ghulTnosj/ryi3ofl74wmYfYheWrPDbAuUguIk1VWosXPe nZ5g== X-Gm-Message-State: AOUpUlECYuMtEf470bpqE+e8yF3gesw0qScEqvxD1kKn+DpDDtSOioVF 0fRLSGlQl6h8YmqdxaNCctfVJ3Rk X-Google-Smtp-Source: AAOMgpcsnI/KxlrWNGL/1888gdFFj5BIdBZCPn2eJkRHCifawEnu+O7Gb/HMZKiyBrhP6PQbjt4eJQ== X-Received: by 2002:a17:902:46e:: with SMTP id 101-v6mr10848698ple.39.1532806872629; Sat, 28 Jul 2018 12:41:12 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:34 +0530 Message-Id: <1532800907-29115-20-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.26]); Sat, 28 Jul 2018 19:41:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 28 Jul 2018 19:41:13 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 19/32] util: netdevtap: 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:41:31 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virnetdevtap.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index d432577..c2c2e73 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -400,16 +400,14 @@ int virNetDevTapCreate(char **ifname, if (strstr(*ifname, "%d") !=3D NULL) { size_t i; for (i =3D 0; i <=3D IF_MAXUNIT; i++) { - char *newname; + VIR_AUTOFREE(char *) newname =3D NULL; if (virAsprintf(&newname, *ifname, i) < 0) goto cleanup; =20 if (virNetDevExists(newname) =3D=3D 0) { - newifname =3D newname; + VIR_STEAL_PTR(newifname, newname); break; } - - VIR_FREE(newname); } if (newifname) { VIR_FREE(*ifname); @@ -423,7 +421,7 @@ int virNetDevTapCreate(char **ifname, } =20 if (tapfd) { - char *dev_path =3D NULL; + VIR_AUTOFREE(char *) dev_path =3D NULL; if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) goto cleanup; =20 @@ -431,11 +429,8 @@ int virNetDevTapCreate(char **ifname, virReportSystemError(errno, _("Unable to open %s"), dev_path); - VIR_FREE(dev_path); goto cleanup; } - - VIR_FREE(dev_path); } =20 if (virNetDevSetName(ifr.ifr_name, *ifname) =3D=3D -1) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806897277839.3743143710166; Sat, 28 Jul 2018 12:41:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B5CA81E03; Sat, 28 Jul 2018 19:41:35 +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 5A8B019219; Sat, 28 Jul 2018 19:41:35 +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 D42011800B6F; Sat, 28 Jul 2018 19:41:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfKDK020930 for ; Sat, 28 Jul 2018 15:41:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47CCC308BDB1; Sat, 28 Jul 2018 19:41:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E591308BDAB for ; Sat, 28 Jul 2018 19:41:16 +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 B1F7D3086246 for ; Sat, 28 Jul 2018 19:41:15 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id a11-v6so5079389pgw.6 for ; Sat, 28 Jul 2018 12:41:15 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:14 -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=Rsj0ZUy7/WOczLv9Vqllu0h5wNOh0tSOaVnkF3URmp0=; b=WPM5ZDufqOu4hNUVIPf9B1dvAaCLK+xholNfb/azd33CYRL3qVyD2MsVmHfDfCtdtR MBHbipcsjCtTgkXMakLZTojq0sQYEA7blM+d9xIN5GZ0+JLiIJL24kVZJUG0buYC0wcc H2QtYAGPHqLTg7DSAZY8N7tmMk1lKBuHByrafefmMSR27ZtbUv1Iwomu2ml1gtCmtKzN gThjwjSRUY56k1gEHhd4A6nKJWoLSI8/vQO+uygk9SSD6snnvj6eVJuKE1aZcZPRmCTd M2STGolzpMcwpGU5ETcAuInNGhBxonU5kJd5ZcGXvpTONHuKCMwSrjmoBW7jh6VKllCX n31A== 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=Rsj0ZUy7/WOczLv9Vqllu0h5wNOh0tSOaVnkF3URmp0=; b=f+tfyarTpfnF1x30JkrvYMq/zJH3vc8KXZyPSJKEWwg6M+QqbQOrzWl3R+9QsaEjSH ZLuJMwNw6SIUY6e17LHb5s35txgR5j4hfy3OrgLMnJpp3f4JVaHhw8X59sJRiI9OMdlW +p+er2sPFrOeBaRE7T9lxgId18RZPun0ZtNQ4fzHZrtS0javQg5fFsv3fME8ZrkKuqpc uK2+QjzzNkOtnFKy8dRuelatid1Osd7wZt7vwls+MFxUbyyzdo/DPgC9jf+AdePRp/5/ RrcK5mEW3v4oeVIric2CuaIGhTAbTBtLQlacchCHnbgY9IxAh9dutqS4OUYtujmaV2K4 d3NA== X-Gm-Message-State: AOUpUlFAXvoJv8zcr6f83h59ItBpPi/WqQ3+I98OLjJ93s/chqtUoTjz 9kgRlEgnhHLcHBCXbJSQ+J69AdbA X-Google-Smtp-Source: AAOMgpdvX20ggb8Uo0X9kCoroRThwCxRulSZUcXPkRwjf2CLOea+Euj80wl055bq4CnTpHJ/240QCw== X-Received: by 2002:a62:5290:: with SMTP id g138-v6mr11794666pfb.46.1532806875011; Sat, 28 Jul 2018 12:41:15 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:35 +0530 Message-Id: <1532800907-29115-21-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.49]); Sat, 28 Jul 2018 19:41:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:41:15 +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.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 20/32] util: netdevveth: 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.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 28 Jul 2018 19:41:36 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virnetdevveth.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 6905168..8c1a7f3 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -46,12 +46,11 @@ virMutex virNetDevVethCreateMutex =3D VIR_MUTEX_INITIAL= IZER; static int virNetDevVethExists(int devNum) { int ret; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0) return -1; ret =3D virFileExists(path) ? 1 : 0; VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret); - VIR_FREE(path); return ret; } =20 @@ -111,8 +110,6 @@ static int virNetDevVethGetFreeNum(int startDev) int virNetDevVethCreate(char** veth1, char** veth2) { int ret =3D -1; - char *veth1auto =3D NULL; - char *veth2auto =3D NULL; int vethNum =3D 0; virCommandPtr cmd =3D NULL; size_t i; @@ -125,6 +122,9 @@ int virNetDevVethCreate(char** veth1, char** veth2) #define MAX_VETH_RETRIES 10 =20 for (i =3D 0; i < MAX_VETH_RETRIES; i++) { + VIR_AUTOFREE(char *) veth1auto =3D NULL; + VIR_AUTOFREE(char *) veth2auto =3D NULL; + int status; if (!*veth1) { int veth1num; @@ -173,8 +173,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) *veth1 ? *veth1 : veth1auto, *veth2 ? *veth2 : veth2auto, status); - VIR_FREE(veth1auto); - VIR_FREE(veth2auto); virCommandFree(cmd); cmd =3D NULL; } @@ -186,8 +184,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) cleanup: virMutexUnlock(&virNetDevVethCreateMutex); virCommandFree(cmd); - VIR_FREE(veth1auto); - VIR_FREE(veth2auto); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806885142928.7010217773644; Sat, 28 Jul 2018 12:41:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45D43307D854; Sat, 28 Jul 2018 19:41:23 +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 131CFCFBF7; Sat, 28 Jul 2018 19:41:23 +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 AE25A1800FED; Sat, 28 Jul 2018 19:41:22 +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 w6SJfJxT020914 for ; Sat, 28 Jul 2018 15:41:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 772C867CEF; Sat, 28 Jul 2018 19:41:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E2A26596C for ; Sat, 28 Jul 2018 19:41:19 +0000 (UTC) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 273DA30832DC for ; Sat, 28 Jul 2018 19:41:18 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id p23-v6so5064894pgv.13 for ; Sat, 28 Jul 2018 12:41:18 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:17 -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=vEPGK9lk9BLYUZZZM03g6X8I6CTAj9H+GNDkP8gCrnU=; b=torHojW9pO63VH7+AuZm6whySvF1wv4jt2YhCLG6KtLFXgy5WiBg7yre5kfbOXf5JC G8j0+6wPWiYjBfRnE63WlkS6D+zEgstvCAn5qJLbVeFuXtFyFueZo+FZFLyH2xE/257r /XXvjo0UVsPgxpdgMiumHlgJLDKkiiVuARuwVl+oIKHXO0S0dDG4J87M0Zj33ZJCveWx sdPs7IV7tnJs2CIxyO/Pj8m4LMIbE66nmDN6NtBrD+eHFlVadoyKUf7A81NhcgSBR+8L lgSeIIr5aT1Uo7Qdnn6ZrCeEHXxiJF6NfnvSxKvZTJvRpsEzlSXyUb70vXD2rmGXZyzD HNYw== 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=vEPGK9lk9BLYUZZZM03g6X8I6CTAj9H+GNDkP8gCrnU=; b=aMdGPtY0VswRpH4QnEUmk/eQT8D2iHvpjbJBJXmxX/tw8vn5UUh3xfAOeIvWy1cyke I53fS0n4raLHOj+nMHH5FELJJWHJV90XpMbeiYP3kv0XZeqONx+hePOUbEVojoOBtCyS d+cK84JDOm/6jdx5fefY62NPCqPUEzMjZgXuBwnBVRa2Rtpz092+0JT0210TWomvNkXc De4Nv+q28CF82Aj0NMjcXLvd9BwlEAeIzdkAIDUVGLJ7avhE65EGn1lmNFVWxtv8U0Bh RMJZgESK5dV++++jsIUI/qzFqWi45NOF82NvjaZEIwz8zXEfekfk1qU6ySJ8XQHsIYdb yt7w== X-Gm-Message-State: AOUpUlGuQIVG+cng40/BLAInD12I75z9eJCYY4d3xHnjr9Nv9A04IZp6 +zw7d18eipEI2oqoUurWZ0hkU2lj X-Google-Smtp-Source: AAOMgpdJTQlLj+RR3xcR6xBZT8eTyZbQx21I3sIYawN1gj4tye7xFOCo0I6Pd0gVnlFHqMz3nnllfw== X-Received: by 2002:a62:9dcc:: with SMTP id a73-v6mr11394409pfk.249.1532806877394; Sat, 28 Jul 2018 12:41:17 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:36 +0530 Message-Id: <1532800907-29115-22-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.44]); Sat, 28 Jul 2018 19:41:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:18 +0000 (UTC) for IP:'209.85.215.172' DOMAIN:'mail-pg1-f172.google.com' HELO:'mail-pg1-f172.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.215.172 mail-pg1-f172.google.com 209.85.215.172 mail-pg1-f172.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 21/32] util: netdevveth: use VIR_AUTOPTR for aggregate 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions 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/virnetdevveth.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 8c1a7f3..0b94f73 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -111,7 +111,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) { int ret =3D -1; int vethNum =3D 0; - virCommandPtr cmd =3D NULL; size_t i; =20 /* @@ -124,6 +123,7 @@ int virNetDevVethCreate(char** veth1, char** veth2) for (i =3D 0; i < MAX_VETH_RETRIES; i++) { VIR_AUTOFREE(char *) veth1auto =3D NULL; VIR_AUTOFREE(char *) veth2auto =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 int status; if (!*veth1) { @@ -173,8 +173,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) *veth1 ? *veth1 : veth1auto, *veth2 ? *veth2 : veth2auto, status); - virCommandFree(cmd); - cmd =3D NULL; } =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -183,7 +181,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) =20 cleanup: virMutexUnlock(&virNetDevVethCreateMutex); - virCommandFree(cmd); return ret; } =20 @@ -200,26 +197,22 @@ int virNetDevVethCreate(char** veth1, char** veth2) */ int virNetDevVethDelete(const char *veth) { - virCommandPtr cmd =3D virCommandNewArgList("ip", "link", "del", veth, = NULL); + VIR_AUTOPTR(virCommand) cmd =3D NULL; + cmd =3D virCommandNewArgList("ip", "link", "del", veth, NULL); int status; - int ret =3D -1; =20 if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; =20 if (status !=3D 0) { if (!virNetDevExists(veth)) { VIR_DEBUG("Device %s already deleted (by kernel namespace clea= nup)", veth); - ret =3D 0; - goto cleanup; + return 0; } virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to delete veth device %s"), veth); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806901238695.0034850204779; Sat, 28 Jul 2018 12:41:41 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7F7AE300270A; Sat, 28 Jul 2018 19:41:39 +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 416A6782D3; Sat, 28 Jul 2018 19:41:39 +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 D15091800B73; Sat, 28 Jul 2018 19:41:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfPx0020957 for ; Sat, 28 Jul 2018 15:41:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B82810694C0; Sat, 28 Jul 2018 19:41:25 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0487A101F979 for ; Sat, 28 Jul 2018 19:41:21 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 28200308FB93 for ; Sat, 28 Jul 2018 19:41:20 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id w3-v6so3733237plq.2 for ; Sat, 28 Jul 2018 12:41:20 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:18 -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=gERKjD9wBk2ZlcpjOVey0Ji86RXUNTtntvfJkEOTrqk=; b=pOTxzgWkPo4PPtoYxedgJy8wunwTpGVzgDARb7LHwcNdw/1sjXP/LhdIJwAQBb72uG B0fqXAzfj6mqv/WFrTiLjM/x4qrxuCkStuncExIah8ODYYWxHF5mC4oZDg3qCytwJ7SC G9X3tRQ70vYGAALD0tK2d5ZClf/Xs0epMoGkfipFlcwhFcdUQUPLeYU4N1FElnL09nhL H1GFxA/IjH0fXioOtN07x/noafvMrkLeTlg1vxbjltiQo6c/B2NNNBw3it/MwV7epa3C 2Pmuddn3ShlH3WdKhPq4KyYau8eo8X/U8xKMCO8vxP5PToGgyD9gP6Ad/YJUyDjHKKSV hkcw== 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=gERKjD9wBk2ZlcpjOVey0Ji86RXUNTtntvfJkEOTrqk=; b=NfBc4OLXFnK/cY2+XvyyFRxp1VHaaPZIaObU0Q61/7hgyrD/DXpLNe/3YWTK5M8JoR zCylt/DMeB7ESNbZykHgFgNj5vebFDu4CgqyRZQFrqw+NtF8sWk6fQrZE4UmFdyVi9IK hwKkt9e0OymuBvT8LZqEvRTfx1rrqu6B3m727+lb2z5Ry1FqIiPCOyp6gr/kXStCnplN AX9uZQQ27T/COJqBcl/Azw4fRoV38JxRqll1MZmlbegAAvaiDpjqS8bWSpdo4H+wumwh 7sSd+QvV7gNql+lbIc0MFSwCYKLQ6dkdvouDed1nAMbydGb646hf7iLA0aSrdOF7+q4A d6nQ== X-Gm-Message-State: AOUpUlFwzow/1S0pC5vkMfcXye+RexS7NPVSVs0LfFc6muO2Yhz3bY0t PTKZwv5KPrFp074tKV0SXLeA0C6f X-Google-Smtp-Source: AAOMgpeh88IlMIFlvFuFnO1j28vJIIGjyWpFQIvRs4tu3uzsXermoTnjd9w9aqPlgWvXWFs4XhM8GQ== X-Received: by 2002:a17:902:7247:: with SMTP id c7-v6mr10785022pll.79.1532806879346; Sat, 28 Jul 2018 12:41:19 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:37 +0530 Message-Id: <1532800907-29115-23-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.43]); Sat, 28 Jul 2018 19:41:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 28 Jul 2018 19:41:20 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 22/32] util: netlink: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:40 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. This commit also adds a typedef for virNetlinkHandlePtr for use with the cleanup macros. When a variable of type virNetlinkHandlePtr is declared using VIR_AUTOPTR, the function virNetlinkFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetlink.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fa1ba3e..8d28387 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -72,6 +72,10 @@ typedef struct nl_handle virNetlinkHandle; typedef struct nl_sock virNetlinkHandle; # endif =20 +typedef virNetlinkHandle *virNetlinkHandlePtr; + +VIR_DEFINE_AUTOPTR_FUNC(virNetlinkHandle, virNetlinkFree) + typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; struct _virNetlinkEventSrvPrivate { @@ -79,7 +83,7 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; - virNetlinkHandle *netlinknh; + virNetlinkHandlePtr netlinknh; /*Events*/ int handled; size_t handlesCount; @@ -102,7 +106,7 @@ static int nextWatch =3D 1; /* Linux kernel supports up to MAX_LINKS (32 at the time) individual * netlink protocols. */ static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] =3D {NULL}; -static virNetlinkHandle *placeholder_nlhandle; +static virNetlinkHandlePtr placeholder_nlhandle; =20 /* Function definitions */ =20 @@ -172,10 +176,10 @@ virNetlinkShutdown(void) * Returns a handle to the new netlink socket, or 0 if there was a failure. * */ -static virNetlinkHandle * +static virNetlinkHandlePtr virNetlinkCreateSocket(int protocol) { - virNetlinkHandle *nlhandle =3D NULL; + virNetlinkHandlePtr nlhandle =3D NULL; =20 if (!(nlhandle =3D virNetlinkAlloc())) { virReportSystemError(errno, "%s", @@ -209,7 +213,7 @@ virNetlinkCreateSocket(int protocol) goto cleanup; } =20 -static virNetlinkHandle * +static virNetlinkHandlePtr virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t src_pid, struct sockaddr_nl nladdr, unsigned int protocol, unsigned int groups) @@ -217,7 +221,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t s= rc_pid, ssize_t nbytes; int fd; int n; - virNetlinkHandle *nlhandle =3D NULL; + virNetlinkHandlePtr nlhandle =3D NULL; struct pollfd fds[1]; struct nlmsghdr *nlmsg =3D nlmsg_hdr(nl_msg); =20 @@ -303,7 +307,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, .nl_groups =3D 0, }; struct pollfd fds[1]; - virNetlinkHandle *nlhandle =3D NULL; + virNetlinkHandlePtr nlhandle =3D NULL; int len =3D 0; =20 memset(fds, 0, sizeof(fds)); @@ -353,7 +357,7 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; - virNetlinkHandle *nlhandle =3D NULL; + virNetlinkHandlePtr nlhandle =3D NULL; =20 if (!(nlhandle =3D virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806896708756.8770353864485; Sat, 28 Jul 2018 12:41:36 -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 EB41B3084047; Sat, 28 Jul 2018 19:41:34 +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 A4F283001A45; Sat, 28 Jul 2018 19:41:34 +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 450321800B6C; Sat, 28 Jul 2018 19:41:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfNIR020947 for ; Sat, 28 Jul 2018 15:41:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D30992010CE7; Sat, 28 Jul 2018 19:41:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C30882010CE6 for ; Sat, 28 Jul 2018 19:41:23 +0000 (UTC) Received: from mail-pl0-f47.google.com (mail-pl0-f47.google.com [209.85.160.47]) (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 4111B307D84A for ; Sat, 28 Jul 2018 19:41:22 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id m1-v6so3726602plt.6 for ; Sat, 28 Jul 2018 12:41:22 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:21 -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=uYJsWhM7Hi+O34SBFM1Gugs+RwkrpM6nhIwUc3lp2XY=; b=GE7YSh8OikTGEPTesg5dQftIlSZshaF9Sx1mK0GuguHc8Wke7AH+sRpo3S1sPe4har BUUQBtf6Uwv0uMVElNBpRkujYwgBRfhNRAfIi92pXNw99rInaxuUAIiKp7U16oWhKeNA HuR6dq2rj2vt1fhbEYofYUFXjZ5gbhHuRKBkCpkPy5v9dlb4vmM4P76Ks4z6kWPQjap1 lxilYLJcNllBzej1rfLJf87jcmuTr6RMOZFlzADlxoJKVmBaKTAXctwDcMkse+ELun8Q iCfiOb7dxlQLgS89F6odU1KqZv8Wdzc9QNnIz/Ye40ybggzji2yB76H8QlODrd6Yc+Tl lZhw== 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=uYJsWhM7Hi+O34SBFM1Gugs+RwkrpM6nhIwUc3lp2XY=; b=bpUmyVqEU9y6WVoRg95hss47teLTTKYPwdQsmzQIuQjOMg/1bbUORt4sPU2Gn1r5eh Ps/3cy//WyWHIMSFuMo3EACBTJvoC1SCkx6oOUXqT5s8xA1UFolCRjY4ihefRFsnD3q/ 2RKaETKwcXRh4QHDnXZovvTG8iAFDd2Ys8aNaCw4SEi9tcRO/NiWpSUCBUTWtFEKjrPY OjN3iH8KOVGn7B1Es13sD9viZdZ2bLIphU9n15pnPdZ4EueOJhk4FkYR/YKcM2YN0GCW daqNWxODc9P6DwSYUbWWYnYMB1wIzkvbqEhYY+Z2NcjzJ0LGhz1DxmgRBOqhxeFl7O4h VOZw== X-Gm-Message-State: AOUpUlHp0uE91sFyixTaQHkyaofYJ6X6V1c96ZU1F7pRbgIJ0QtWLSQs LGvNPOTKqIZFvpyL0d58MTKPa1gB X-Google-Smtp-Source: AAOMgpf9j9TrPaXHn1oOGWBCrnZUFE3NKeYPdK35nyhkLXBwpN25keu+beepy3SPfFFGuGuVQvfFNg== X-Received: by 2002:a17:902:b81:: with SMTP id 1-v6mr10877738plr.164.1532806881530; Sat, 28 Jul 2018 12:41:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:38 +0530 Message-Id: <1532800907-29115-24-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.48]); Sat, 28 Jul 2018 19:41:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:22 +0000 (UTC) for IP:'209.85.160.47' DOMAIN:'mail-pl0-f47.google.com' HELO:'mail-pl0-f47.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.160.47 mail-pl0-f47.google.com 209.85.160.47 mail-pl0-f47.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 23/32] util: netlink: use VIR_AUTOPTR for aggregate 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.40]); Sat, 28 Jul 2018 19:41:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetlink.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 8d28387..6b00559 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -221,30 +221,31 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t= src_pid, ssize_t nbytes; int fd; int n; - virNetlinkHandlePtr nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; + virNetlinkHandlePtr temp =3D NULL; struct pollfd fds[1]; struct nlmsghdr *nlmsg =3D nlmsg_hdr(nl_msg); =20 if (protocol >=3D MAX_LINKS) { virReportSystemError(EINVAL, _("invalid protocol argument: %d"), protocol); - goto error; + return NULL; } =20 if (!(nlhandle =3D virNetlinkCreateSocket(protocol))) - goto error; + return NULL; =20 fd =3D nl_socket_get_fd(nlhandle); if (fd < 0) { virReportSystemError(errno, "%s", _("cannot get netlink socket fd")); - goto error; + return NULL; } =20 if (groups && nl_socket_add_membership(nlhandle, groups) < 0) { virReportSystemError(errno, "%s", _("cannot add netlink membership")); - goto error; + return NULL; } =20 nlmsg_set_dst(nl_msg, &nladdr); @@ -255,7 +256,7 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t s= rc_pid, if (nbytes < 0) { virReportSystemError(errno, "%s", _("cannot send to netlink socket")); - goto error; + return NULL; } =20 memset(fds, 0, sizeof(fds)); @@ -273,11 +274,9 @@ virNetlinkSendRequest(struct nl_msg *nl_msg, uint32_t = src_pid, _("no valid netlink response was received= ")); } =20 - return nlhandle; + VIR_STEAL_PTR(temp, nlhandle); =20 - error: - virNetlinkFree(nlhandle); - return NULL; + return temp; } =20 /** @@ -307,7 +306,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, .nl_groups =3D 0, }; struct pollfd fds[1]; - virNetlinkHandlePtr nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; int len =3D 0; =20 memset(fds, 0, sizeof(fds)); @@ -335,7 +334,6 @@ int virNetlinkCommand(struct nl_msg *nl_msg, *respbuflen =3D 0; } =20 - virNetlinkFree(nlhandle); return ret; } =20 @@ -346,10 +344,8 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, unsigned int protocol, unsigned int groups, void *opaque) { - int ret =3D -1; bool end =3D false; int len =3D 0; - struct nlmsghdr *resp =3D NULL; struct nlmsghdr *msg =3D NULL; =20 struct sockaddr_nl nladdr =3D { @@ -357,13 +353,14 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; - virNetlinkHandlePtr nlhandle =3D NULL; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; =20 if (!(nlhandle =3D virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) - goto cleanup; + return -1; =20 while (!end) { + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; len =3D nl_recv(nlhandle, &nladdr, (unsigned char **)&resp, NULL); VIR_WARNINGS_NO_CAST_ALIGN for (msg =3D resp; NLMSG_OK(msg, len); msg =3D NLMSG_NEXT(msg, len= )) { @@ -372,20 +369,14 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, end =3D true; =20 if (virNetlinkGetErrorCode(msg, len) < 0) - goto cleanup; + return -1; =20 if (callback(msg, opaque) < 0) - goto cleanup; + return -1; } - VIR_FREE(resp); } =20 - ret =3D 0; - - cleanup: - VIR_FREE(resp); - virNetlinkFree(nlhandle); - return ret; + return 0; } =20 /** @@ -527,7 +518,7 @@ int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; @@ -582,7 +573,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -771,7 +761,7 @@ virNetlinkEventCallback(int watch, void *opaque) { virNetlinkEventSrvPrivatePtr srv =3D opaque; - struct nlmsghdr *msg; + VIR_AUTOFREE(struct nlmsghdr *) msg =3D NULL; struct sockaddr_nl peer; struct ucred *creds =3D NULL; size_t i; @@ -806,7 +796,7 @@ virNetlinkEventCallback(int watch, =20 if (!handled) VIR_DEBUG("event not handled."); - VIR_FREE(msg); + virNetlinkEventServerUnlock(srv); } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806905578804.4139502081606; Sat, 28 Jul 2018 12:41:45 -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 E113C81DF7; Sat, 28 Jul 2018 19:41:43 +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 AA6C4600C8; Sat, 28 Jul 2018 19:41:43 +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 61B7A24F64; Sat, 28 Jul 2018 19:41:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfUT6020999 for ; Sat, 28 Jul 2018 15:41:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E143CFBFC; Sat, 28 Jul 2018 19:41:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57503CFBFB for ; Sat, 28 Jul 2018 19:41:25 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (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 6FE4A30832F1 for ; Sat, 28 Jul 2018 19:41:24 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id f6-v6so3740140plo.1 for ; Sat, 28 Jul 2018 12:41:24 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:23 -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=vnrGKgfJdan7YcDiZ/xwGDyOzEPOItqKpYfudfk+WKY=; b=Je4+X6CH+oQAD6eYb7i6uENPXUsJ5mRhBe7Ug/ujkusUPtw6fcbHGS2WGABJNMMaZy a/47MKpPoXx/UP0AdQ0oI+7/Q1xw4xdEJOQhstOcaDvfS2vhJJyUli3kg/ES5QS+jOu0 78Gwes4WcaHj/T5Q2RIEnhfRr2TRPEmTMwzKgESdtvM/pYpsOrPGI7uu9Gekx/uMvFgp WV3ObfSqo2aG9jVPWKGrp+0S+nSxtgZeQzUYczaOG07pSLEMlHR4aUE3skyRq3PQr3Ln GKvhMT30ShA+ZyLJCU780QT6eyn18bn1dSmim6P6z2F2hEKOL1NvwyL7xENpteUUZnzW jYeQ== 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=vnrGKgfJdan7YcDiZ/xwGDyOzEPOItqKpYfudfk+WKY=; b=TJ5lRwP04HkCXuEj9f9bjvYEry2Q3vNSWx+ZAPrmwX5qrUqZWprqMUyu/wS/imBTKQ cSWoKwRjVaQuGjcBzWQd/eVm1K3Ik/oJhbnoeFZWLEcC5toxT5mRAM/wY5kCM3P6237v /asA6PmWrPzQ+AZg4vQQZYSTLWN0t58qKbwlTvrAA35Il6yb9vc6mRAupyH28tbqiTy6 3iwfbXSWg4IHhJMWZlyb82XBXnWBKFoedAUJbY2YT1GtWzjr0RWpAWpSDDY0YYSBl4OS 78cObsKmuWGCZss4wp0mU91/nwXdQOmxCltPiZmhxHum5nILGwS2gYypZRfw53bJal7B ZD7A== X-Gm-Message-State: AOUpUlE6H5phiA23fWR+Shglbn3UYlS6OxZlcKVMVoZLTqfGIyH7yWHr KdktEO3pXXKkEdzoqlSPdsXREfRw X-Google-Smtp-Source: AAOMgpdiDZqRsru8pITDlE/SLknITwgQDOwmopW5le53V9f7MLTT8bbCo5FI382/RZ+kNJnOv/rDwQ== X-Received: by 2002:a17:902:820a:: with SMTP id x10-v6mr10713254pln.261.1532806883750; Sat, 28 Jul 2018 12:41:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:39 +0530 Message-Id: <1532800907-29115-25-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.44]); Sat, 28 Jul 2018 19:41:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:24 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 24/32] util: numa: 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.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.25]); Sat, 28 Jul 2018 19:41:44 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virnuma.c | 79 +++++++++++++++++++++-----------------------------= ---- 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 784db0a..841c7cb 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -252,8 +252,8 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { - unsigned long *mask =3D NULL; - unsigned long *allonesmask =3D NULL; + VIR_AUTOFREE(unsigned long *) mask =3D NULL; + VIR_AUTOFREE(unsigned long *) allonesmask =3D NULL; virBitmapPtr cpumap =3D NULL; int ncpus =3D 0; int max_n_cpus =3D virNumaGetMaxCPUs(); @@ -300,8 +300,6 @@ virNumaGetNodeCPUs(int node, ret =3D ncpus; =20 cleanup: - VIR_FREE(mask); - VIR_FREE(allonesmask); virBitmapFree(cpumap); =20 return ret; @@ -566,52 +564,47 @@ virNumaGetHugePageInfo(int node, unsigned long long *page_avail, unsigned long long *page_free) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *end; =20 if (page_avail) { + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; if (virNumaGetHugePageInfoPath(&path, node, page_size, "nr_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_avail) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } - VIR_FREE(buf); - VIR_FREE(path); } =20 if (page_free) { + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; if (virNumaGetHugePageInfoPath(&path, node, page_size, "free_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_free) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 /** @@ -714,13 +707,13 @@ virNumaGetPages(int node, size_t *npages) { int ret =3D -1; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(unsigned int *) tmp_size =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_avail =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_free =3D NULL; DIR *dir =3D NULL; int direrr =3D 0; struct dirent *entry; - unsigned int *tmp_size =3D NULL; - unsigned long long *tmp_avail =3D NULL; - unsigned long long *tmp_free =3D NULL; unsigned int ntmp =3D 0; size_t i; bool exchange; @@ -828,11 +821,7 @@ virNumaGetPages(int node, *npages =3D ntmp; ret =3D 0; cleanup: - VIR_FREE(tmp_free); - VIR_FREE(tmp_avail); - VIR_FREE(tmp_size); VIR_DIR_CLOSE(dir); - VIR_FREE(path); return ret; } =20 @@ -843,8 +832,8 @@ virNumaSetPagePoolSize(int node, unsigned long long page_count, bool add) { - int ret =3D -1; - char *nr_path =3D NULL, *nr_buf =3D NULL; + VIR_AUTOFREE(char *) nr_path =3D NULL; + VIR_AUTOFREE(char *) nr_buf =3D NULL; char *end; unsigned long long nr_count; =20 @@ -853,37 +842,35 @@ virNumaSetPagePoolSize(int node, * differently to huge pages. */ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("system pages pool can't be modified")); - goto cleanup; + return -1; } =20 if (virNumaGetHugePageInfoPath(&nr_path, node, page_size, "nr_hugepage= s") < 0) - goto cleanup; + return -1; =20 /* Firstly check, if there's anything for us to do */ if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (add) { if (!page_count) { VIR_DEBUG("Nothing left to do: add =3D true page_count =3D 0"); - ret =3D 0; - goto cleanup; + return 0; } page_count +=3D nr_count; } else { if (nr_count =3D=3D page_count) { VIR_DEBUG("Nothing left to do: nr_count =3D page_count =3D %ll= u", page_count); - ret =3D 0; - goto cleanup; + return 0; } } =20 @@ -896,40 +883,36 @@ virNumaSetPagePoolSize(int node, */ VIR_FREE(nr_buf); if (virAsprintf(&nr_buf, "%llu", page_count) < 0) - goto cleanup; + return -1; =20 if (virFileWriteStr(nr_path, nr_buf, 0) < 0) { virReportSystemError(errno, _("Unable to write to: %s"), nr_path); - goto cleanup; + return -1; } =20 /* And now do the check. */ =20 VIR_FREE(nr_buf); if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (nr_count !=3D page_count) { virReportError(VIR_ERR_OPERATION_FAILED, _("Unable to allocate %llu pages. Allocated only %l= lu"), page_count, nr_count); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(nr_buf); - VIR_FREE(nr_path); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 15328069069191011.2822000089348; Sat, 28 Jul 2018 12:41:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0468EC04B31C; Sat, 28 Jul 2018 19:41:45 +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 AA5A51073049; Sat, 28 Jul 2018 19:41:44 +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 4C7E524F56; Sat, 28 Jul 2018 19:41:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfU76021014 for ; Sat, 28 Jul 2018 15:41:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id C86F73001A5A; Sat, 28 Jul 2018 19:41:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C03883001A65 for ; Sat, 28 Jul 2018 19:41:27 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 259AC307D84A for ; Sat, 28 Jul 2018 19:41:27 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id j8-v6so2879163pff.6 for ; Sat, 28 Jul 2018 12:41:27 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:26 -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=CE253mAFU/kXPfvjrB9gVytj4AI8T7X5GJWf6vbDx64=; b=YH/srhdwBDzeS0ygK97ATLSveKll0d6U2ncUkKX9xBAE4/9y6TwVDcV6rSDeR3vmkp 0+sKFCI8xHuPcDdG2B6+0EcR1p9L5DALsREc8ac/dFSE9UrwqAsaij/tXLe9Rl9VutL6 oglXLgRNeC5YHyPY5dyJdqIhnUwhAtxqoKssm1+MWQCIw+tWOZUw/+BoN3gmgGXlMbAR tYZCFjRjZLc1Wq5zioMticl+Nwl8pwMARvhSdDTMdZldkm/B+o9Mmgyax3JQYm8RFp12 rdNqb2hL2YS5OcGs/eW6qVK3NcQBrkIUy9jf+qwG790kKrszeBwmocLjOwWAttJV5yWL o5UQ== 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=CE253mAFU/kXPfvjrB9gVytj4AI8T7X5GJWf6vbDx64=; b=L4tvyEC1ydkRo0GD/Dymg4ZkNEtlKZxOnCHY+xCEygrvHlUhxbsmloX9USrM9a7GiU COBV+NnBq4dcqduCN/ClQDz5S5HRJdazW2d2+5sdQQSPdnybALzvVf+wIZzrQfeA0MxO ZAaTIPGfVdApmRZK/BVKY9mpQsS9MFsvRtus1DWXkdG60QVEBYd++GOPUXpnu50iwEmq gsGV3l8qHEL4gHF98PNNLr7CWRoqdEQdK/vX//gkprHReU//shh98lReUsUfDPYcNppt X9bUL0nvbsmmEgAk2Mz8j1K1BsC3h8ph2cyxG3N/QavEybahTa8pZEx8r4VaXHKixjnq ZYYQ== X-Gm-Message-State: AOUpUlElll4ixWHSCKRYF7YORr60QCIkd5rUQMGFujUQmtcD0zmEK0ND UJX4haeMJTf4GWIciVAGESyRWqEy X-Google-Smtp-Source: AAOMgpfIO3RxYBElM4E3R0XV+zpfvjvDCBsOmFOkZICw40oUkjm8oPMLpyZVjvojuZs1Uus7U/r5fA== X-Received: by 2002:a62:34c4:: with SMTP id b187-v6mr11607808pfa.15.1532806886455; Sat, 28 Jul 2018 12:41:26 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:40 +0530 Message-Id: <1532800907-29115-26-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.48]); Sat, 28 Jul 2018 19:41:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 28 Jul 2018 19:41:27 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 25/32] util: numa: use VIR_AUTOPTR for aggregate 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 28 Jul 2018 19:41:45 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnuma.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 841c7cb..fde46ec 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -57,7 +57,7 @@ char * virNumaGetAutoPlacementAdvice(unsigned short vcpus, unsigned long long balloon) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; char *output =3D NULL; =20 cmd =3D virCommandNewArgList(NUMAD, "-w", NULL); @@ -71,7 +71,6 @@ virNumaGetAutoPlacementAdvice(unsigned short vcpus, _("Failed to query numad for the " "advisory nodeset")); =20 - virCommandFree(cmd); return output; } #else /* !HAVE_NUMAD */ @@ -252,41 +251,38 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { + VIR_AUTOPTR(virBitmap) cpumap =3D NULL; VIR_AUTOFREE(unsigned long *) mask =3D NULL; VIR_AUTOFREE(unsigned long *) allonesmask =3D NULL; - virBitmapPtr cpumap =3D NULL; int ncpus =3D 0; int max_n_cpus =3D virNumaGetMaxCPUs(); int mask_n_bytes =3D max_n_cpus / 8; size_t i; - int ret =3D -1; =20 *cpus =3D NULL; =20 if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 memset(allonesmask, 0xff, mask_n_bytes); =20 /* The first time this returns -1, ENOENT if node doesn't exist... */ if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) { VIR_WARN("NUMA topology for cell %d is not available, ignoring", n= ode); - ret =3D -2; - goto cleanup; + return -2; } =20 /* second, third... times it returns an all-1's mask */ if (memcmp(mask, allonesmask, mask_n_bytes) =3D=3D 0) { VIR_DEBUG("NUMA topology for cell %d is invalid, ignoring", node); - ret =3D -2; - goto cleanup; + return -2; } =20 if (!(cpumap =3D virBitmapNew(max_n_cpus))) - goto cleanup; + return -1; =20 for (i =3D 0; i < max_n_cpus; i++) { if (MASK_CPU_ISSET(mask, i)) { @@ -295,14 +291,8 @@ virNumaGetNodeCPUs(int node, } } =20 - *cpus =3D cpumap; - cpumap =3D NULL; - ret =3D ncpus; - - cleanup: - virBitmapFree(cpumap); - - return ret; + VIR_STEAL_PTR(*cpus, cpumap); + return ncpus; } # undef MASK_CPU_ISSET # undef n_bits --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806902392567.3999806159457; Sat, 28 Jul 2018 12:41:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1264300177A; Sat, 28 Jul 2018 19:41:40 +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 7CBDCCFC0B; Sat, 28 Jul 2018 19:41:40 +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 2F3A924F63; Sat, 28 Jul 2018 19:41:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfUP5020998 for ; Sat, 28 Jul 2018 15:41:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C419308BDB3; Sat, 28 Jul 2018 19:41:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52045308BDB2 for ; Sat, 28 Jul 2018 19:41:30 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 33EE1BDC1 for ; Sat, 28 Jul 2018 19:41:29 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id x5-v6so5074863pgp.7 for ; Sat, 28 Jul 2018 12:41:29 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:28 -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=XYr6Wvs6VRnRK4dTT6xI/ZKGnQ8Js9Ahbhk7/9eUfnk=; b=A6mhh7Ixk6uMCgJPcZQsUytCYDEPr6JSbWQLdJ4zdaiJGcKX28sxRRKFs3vqsUiEuq 5YlfWULn/7GQcICJre8o34xlTzgsrnRhFnUcGWK+bj+QNBYPNPdh7ijN0i4yCIo7jLFO l0rxEmkdXioYICIrGAiI+WJ1jK2WYlLyCeTYMUitWpdfJjV9yr9NOOsQIsDPl94ZFQq6 b9cOv/a8EzA/oKcMV4981lX0BnfdFIaImxdujWqwMfoy2qnk5/m1XMA4bXJRySjsWCnM WNFKkCFvFKZifEko7JgvRnoyjgNtkQmmzVJu2CgYmPQMpK45CUpFDBVzSlD7+qWMHvvc 3mLA== 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=XYr6Wvs6VRnRK4dTT6xI/ZKGnQ8Js9Ahbhk7/9eUfnk=; b=KGAFwrJS1imRfIx8YwibGzLyrbHuc00CsHxWs8M2e6TjSjY19KGknHS9wDm7FBx7PC sn7zFjofEaCyP0rNlJSJPjFK5Cw/qk97L0jc/60os4aMY0hgbpjHFcq8FJ3r0cDyHJDT kFi8eznFJhR/I+ubg/OgPfOHWXUj4B1ZFnoyBt1FWTJAS4QY6Ji1KAME57psPLc02L+I eJ1spilDu2MKtYlKs8Ba8EL0ovyFlLqzCY+TU8Z+5ma+e4xRJA2GcNHlQRsrxsdflwKC f6MT308G20h5ivIzDQQjCMNp0PFuMwiIu6An6Xj5+1zDv34qiYOiQKS+z0rwO3dG6OKJ nHGg== X-Gm-Message-State: AOUpUlFWwzEmbdCzdNy0rtmEXAggVlfMHZb0tXmawwIdRvNFVB7Q5T29 IPHw+d7h7TXXxK0QK05WprtSCXw2 X-Google-Smtp-Source: AAOMgpcE01Wdn2UUV27lawGuo1iXtgANmKELHWOdbx7Twa6Llc5hjclTCJGPnx04qN4lHAj3+w167A== X-Received: by 2002:a62:e30c:: with SMTP id g12-v6mr11808669pfh.25.1532806888505; Sat, 28 Jul 2018 12:41:28 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:41 +0530 Message-Id: <1532800907-29115-27-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.29]); Sat, 28 Jul 2018 19:41:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 28 Jul 2018 19:41:29 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 26/32] util: perf: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:41 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virPerfPtr is declared using VIR_AUTOPTR, the function virPerfFree will be run automatically on it when it goes out of scope. This commit also adds an intermediate typedef for virPerf type for use with the cleanup macros. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virperf.c | 3 +-- src/util/virperf.h | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/virperf.c b/src/util/virperf.c index 2c832b3..4537cd0 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -26,7 +26,6 @@ #endif =20 #include "virperf.h" -#include "viralloc.h" #include "virerror.h" #include "virlog.h" #include "virfile.h" @@ -61,7 +60,7 @@ struct virPerfEvent { }; typedef struct virPerfEvent *virPerfEventPtr; =20 -struct virPerf { +struct _virPerf { struct virPerfEvent events[VIR_PERF_EVENT_LAST]; }; =20 diff --git a/src/util/virperf.h b/src/util/virperf.h index eee7a03..9d0d5ac 100644 --- a/src/util/virperf.h +++ b/src/util/virperf.h @@ -23,6 +23,7 @@ # define __VIR_PERF_H__ =20 # include "virutil.h" +# include "viralloc.h" =20 /* Some Intel processor families introduced some RDT (Resource Director * Technology) features to monitor or control shared resource based on @@ -62,8 +63,9 @@ typedef enum { =20 VIR_ENUM_DECL(virPerfEvent); =20 -struct virPerf; -typedef struct virPerf *virPerfPtr; +struct _virPerf; +typedef struct _virPerf virPerf; +typedef virPerf *virPerfPtr; =20 virPerfPtr virPerfNew(void); =20 @@ -83,4 +85,6 @@ int virPerfReadEvent(virPerfPtr perf, virPerfEventType type, uint64_t *value); =20 +VIR_DEFINE_AUTOPTR_FUNC(virPerf, virPerfFree) + #endif /* __VIR_PERF_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 153280691872325.34982182100123; Sat, 28 Jul 2018 12:41:58 -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 00FFF5F728; Sat, 28 Jul 2018 19:41:57 +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 C778660175; Sat, 28 Jul 2018 19:41:56 +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 8129DEEFB; Sat, 28 Jul 2018 19:41:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfkhr021167 for ; Sat, 28 Jul 2018 15:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 94075194B1; Sat, 28 Jul 2018 19:41:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 722F919486 for ; Sat, 28 Jul 2018 19:41:32 +0000 (UTC) Received: from mail-pl0-f45.google.com (mail-pl0-f45.google.com [209.85.160.45]) (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 931D130832EE for ; Sat, 28 Jul 2018 19:41:31 +0000 (UTC) Received: by mail-pl0-f45.google.com with SMTP id 6-v6so3728556plb.0 for ; Sat, 28 Jul 2018 12:41:31 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:30 -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=a8uWO4D64usHLlIk3lc2u+2yGlXYTsl4aUW3S3TZ84c=; b=A6yhlXMwLkRPWh42Wq5vNVsSVuvcqjiLSBUfslYXv/ld4KMlXt6MheGZNd5/FEl1mE zkbOmKI2YZT5jcPBnP2gDZG/oMoaDUQwJ8mqjZE0+sbxMIfWj0pQk54eHWaH/vOWX1Y1 kVBCLebEisdRPoxCR3nw052jbp7uszTxbe+VoiICF7ejTsZ9Jg5KIp7FmepbSoO7Rd+d Ajths2UGDp1Imsd24BVpmgXWg4rp+tLh5lP/mwnz/NGw3SK/vFV5A97jF1HY9ccAwvA6 r+ehkVC/c5vKYghX6bsmuUDpNuA+2NHro2elCs5ZpwTd/JevdruI0wtqQQaGLKcZfbBm y6AA== 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=a8uWO4D64usHLlIk3lc2u+2yGlXYTsl4aUW3S3TZ84c=; b=thVgBgi0GajmGmLbjtk/KNn6FpNpup/aHON6mZsP5iwr8AwM5j0Fqg+iL5zHfqDXyu XVrSlnwGgWzASuuiRYZWfC1CaJnoRmYwkTn8FpiW9AFYs2g6EYVfpzqFXl5Vv5/0ge4I bIjIM4+oMQYRx5e1aidkBVoaIgSUbwT8xhmt3iyV1sm0eD24ammve6hLkJN1WYGHIpve 3VRqCwTBNCX6XWEXnyb1+6wjcfwELy2G7+zfhA5T6knCtZrH3fTqpSzUys5odukY1ygO 4WnWNMB9QHcEv9FP0lXbYUiXSbYR7G3EtN1Q7MAnOnW4kO/LFyi/cTsE/eonp+s78Enh tekg== X-Gm-Message-State: AOUpUlFEJYvmUDKfBeQ7olzhCLcTxls+dj3I6JGIN1aZL5iWiJjaTRH3 dHUwg0PpSB76UWEvP+w//lE+PE8l X-Google-Smtp-Source: AAOMgpfQnjm7aTqS9sOpiqrbQC7iFrY/bf/v29AKo/EN7KMpvqx9jtQi+BsaLL61V3EkWfhWOnI8KA== X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr10656626plo.196.1532806890888; Sat, 28 Jul 2018 12:41:30 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:42 +0530 Message-Id: <1532800907-29115-28-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.44]); Sat, 28 Jul 2018 19:41:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:31 +0000 (UTC) for IP:'209.85.160.45' DOMAIN:'mail-pl0-f45.google.com' HELO:'mail-pl0-f45.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.160.45 mail-pl0-f45.google.com 209.85.160.45 mail-pl0-f45.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 27/32] util: perf: 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.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.39]); Sat, 28 Jul 2018 19:41:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virperf.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/util/virperf.c b/src/util/virperf.c index 4537cd0..1203a6e 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -175,12 +175,12 @@ typedef struct virPerfEventAttr *virPerfEventAttrPtr; static int virPerfRdtAttrInit(void) { - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *tmp =3D NULL; unsigned int attr_type =3D 0; =20 if (virFileReadAllQuiet("/sys/devices/intel_cqm/type", 10, &buf) < 0) - goto error; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -188,19 +188,14 @@ virPerfRdtAttrInit(void) if (virStrToLong_ui(buf, NULL, 10, &attr_type) < 0) { virReportSystemError(errno, "%s", _("failed to get rdt event type")); - goto error; + return -1; } - VIR_FREE(buf); =20 attrs[VIR_PERF_EVENT_CMT].attrType =3D attr_type; attrs[VIR_PERF_EVENT_MBMT].attrType =3D attr_type; attrs[VIR_PERF_EVENT_MBML].attrType =3D attr_type; =20 return 0; - - error: - VIR_FREE(buf); - return -1; } =20 =20 @@ -209,7 +204,6 @@ virPerfEventEnable(virPerfPtr perf, virPerfEventType type, pid_t pid) { - char *buf =3D NULL; struct perf_event_attr attr; virPerfEventPtr event =3D &(perf->events[type]); virPerfEventAttrPtr event_attr =3D &attrs[type]; @@ -227,6 +221,8 @@ virPerfEventEnable(virPerfPtr perf, } =20 if (type =3D=3D VIR_PERF_EVENT_CMT) { + VIR_AUTOFREE(char *) buf =3D NULL; + if (virFileReadAll("/sys/devices/intel_cqm/events/llc_occupancy.sc= ale", 10, &buf) < 0) goto error; @@ -236,8 +232,6 @@ virPerfEventEnable(virPerfPtr perf, _("failed to get cmt scaling factor")); goto error; } - - VIR_FREE(buf); } =20 memset(&attr, 0, sizeof(attr)); @@ -268,7 +262,6 @@ virPerfEventEnable(virPerfPtr perf, =20 error: VIR_FORCE_CLOSE(event->fd); - VIR_FREE(buf); return -1; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 15328069161511012.0094699319477; Sat, 28 Jul 2018 12:41:56 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 8376B4E4C6; Sat, 28 Jul 2018 19:41:53 +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 4ECD4782CE; Sat, 28 Jul 2018 19:41:53 +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 E38A724F5D; Sat, 28 Jul 2018 19:41:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfkqm021161 for ; Sat, 28 Jul 2018 15:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8DF04308BDB8; Sat, 28 Jul 2018 19:41:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84FF9308BDB5 for ; Sat, 28 Jul 2018 19:41:35 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 68D3B12C2B for ; Sat, 28 Jul 2018 19:41:34 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id t17-v6so3720786ply.13 for ; Sat, 28 Jul 2018 12:41:34 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:33 -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=Br5iRtKn1JMnrNeNb6/VUycSKzCXXgu/FEOYh/3JtI4=; b=lozjyqO8/RkPjoxfcd+2McEd5w/1Ir8DipRHjslHzRhbkkQfj+akHbS7dS9JgHzwuP cw+usxXnDV53C87TR7dOR12AyybqyKp/GS99vb7FBo2XEqCRllUCUG2MCOYBPWx5m4G1 emiHQp+naMq1jZH0lWu/ImKybdnyaNUOwzalF662d3ROUTMwBn4TOfjRfj81Et7JIKn9 yj/e7Ifpf15HFZS2HIhRYSVhS2SF8dciQdnF0DBl6CDFt5t38fCtVgZ3EleAJxdFaXT4 UiyPDlfx2q8RASJD4qC7CJaKc/hrZNiPrfGr9gUAY7qxQrQFUF6vj0PisTzp+sIRO56p zU1g== 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=Br5iRtKn1JMnrNeNb6/VUycSKzCXXgu/FEOYh/3JtI4=; b=Zo1dYGiP9RlB2PKTg3YVEvU1KoEb2E1bzQOJuXjBOF8InjDRnNhJFL6oqHfgYc4WZz nIMgmZzaAeHlynGb7b2+FK5TMKTCJCAQWihwv83Sxn7zGoJ91IdThHGoCqeqf4nTj0Gq tngQKW6C8QHKD3dGot53ais13nPM2O5JZFojNEeYfXfrSWMGQBKk3qeAzzA4eG4z17bs +sgKF4c4pV8oBRp3M1doHqHkSHEKqaGzrNdkQKgNgYMmsUtPxxM7OlqlmcYhoDgBQhyc q9o0THXrMnhdZqTGD9wqZrCigVzr2GEEQ35DgYkGtpfH0p2UBTjoEiJl/87cIT+kFfAV b4KA== X-Gm-Message-State: AOUpUlFYb+2kwnN2nHr1HABqpQ/+6igIUbrwmMg+sIi8HUvjLCbdfXuB uFGlPobwYstKwnpufFcWtAmWYcyU X-Google-Smtp-Source: AAOMgpfgmqR5XbklcT3wUTgyIeBCurm7utmHg/36S40KXvO1qtt0MQzWuUzSoY/WPC+rDfUY8jbhhg== X-Received: by 2002:a17:902:18a:: with SMTP id b10-v6mr10874038plb.62.1532806893688; Sat, 28 Jul 2018 12:41:33 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:43 +0530 Message-Id: <1532800907-29115-29-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.26]); Sat, 28 Jul 2018 19:41:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 28 Jul 2018 19:41:34 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 28/32] util: pidfile: 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 28 Jul 2018 19:41:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virpidfile.c | 185 ++++++++++++++++------------------------------= ---- 1 file changed, 59 insertions(+), 126 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 1a85d43..d82bf92 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -97,29 +97,18 @@ int virPidFileWrite(const char *dir, const char *name, pid_t pid) { - int rc; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (virFileMakePath(dir) < 0) { - rc =3D -errno; - goto cleanup; - } + if (virFileMakePath(dir) < 0) + return -errno; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileWritePath(pidfile, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileWritePath(pidfile, pid); } =20 =20 @@ -170,25 +159,16 @@ int virPidFileRead(const char *dir, const char *name, pid_t *pid) { - int rc; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; *pid =3D 0; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReadPath(pidfile, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReadPath(pidfile, pid); } =20 =20 @@ -219,11 +199,11 @@ int virPidFileReadPathIfAlive(const char *path, { int ret; bool isLink; - char *procPath =3D NULL; - char *procLink =3D NULL; + VIR_AUTOFREE(char *) procPath =3D NULL; + VIR_AUTOFREE(char *) procLink =3D NULL; + VIR_AUTOFREE(char *) resolvedBinPath =3D NULL; + VIR_AUTOFREE(char *) resolvedProcLink =3D NULL; size_t procLinkLen; - char *resolvedBinPath =3D NULL; - char *resolvedProcLink =3D NULL; const char deletedText[] =3D " (deleted)"; size_t deletedTextLen =3D strlen(deletedText); pid_t retPid; @@ -232,7 +212,7 @@ int virPidFileReadPathIfAlive(const char *path, *pid =3D -1; =20 if ((ret =3D virPidFileReadPath(path, &retPid)) < 0) - goto cleanup; + return ret; =20 #ifndef WIN32 /* Check that it's still alive. Safe to skip this sanity check on @@ -252,13 +232,12 @@ int virPidFileReadPathIfAlive(const char *path, goto cleanup; } =20 - if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0) { - ret =3D -ENOMEM; - goto cleanup; - } + if (virAsprintf(&procPath, "/proc/%lld/exe", (long long)retPid) < 0) + return -ENOMEM; =20 if ((ret =3D virFileIsLink(procPath)) < 0) - goto cleanup; + return ret; + isLink =3D ret; =20 if (isLink && virFileLinkPointsTo(procPath, binPath)) { @@ -275,27 +254,21 @@ int virPidFileReadPathIfAlive(const char *path, * "$procpath (deleted)". Read that link, remove the " (deleted)" * part, and see if it has the same canonicalized name as binpath. */ - if (!(procLink =3D areadlink(procPath))) { - ret =3D -errno; - goto cleanup; - } + if (!(procLink =3D areadlink(procPath))) + return -errno; + procLinkLen =3D strlen(procLink); if (procLinkLen > deletedTextLen) procLink[procLinkLen - deletedTextLen] =3D 0; =20 if ((ret =3D virFileResolveAllLinks(binPath, &resolvedBinPath)) < 0) - goto cleanup; + return ret; if ((ret =3D virFileResolveAllLinks(procLink, &resolvedProcLink)) < 0) - goto cleanup; + return ret; =20 ret =3D STREQ(resolvedBinPath, resolvedProcLink) ? 0 : -1; =20 cleanup: - VIR_FREE(procPath); - VIR_FREE(procLink); - VIR_FREE(resolvedProcLink); - VIR_FREE(resolvedBinPath); - /* return the originally set pid of -1 unless we proclaim success */ if (ret =3D=3D 0) *pid =3D retPid; @@ -326,24 +299,15 @@ int virPidFileReadIfAlive(const char *dir, pid_t *pid, const char *binpath) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReadPathIfAlive(pidfile, pid, binpath); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReadPathIfAlive(pidfile, pid, binpath); } =20 =20 @@ -361,24 +325,15 @@ int virPidFileDeletePath(const char *pidfile) int virPidFileDelete(const char *dir, const char *name) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileDeletePath(pidfile); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileDeletePath(pidfile); } =20 int virPidFileAcquirePath(const char *path, @@ -470,24 +425,15 @@ int virPidFileAcquire(const char *dir, bool waitForLock, pid_t pid) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileAcquirePath(pidfile, waitForLock, pid); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileAcquirePath(pidfile, waitForLock, pid); } =20 =20 @@ -518,24 +464,15 @@ int virPidFileRelease(const char *dir, const char *name, int fd) { - int rc =3D 0; - char *pidfile =3D NULL; + VIR_AUTOFREE(char *) pidfile =3D NULL; =20 - if (name =3D=3D NULL || dir =3D=3D NULL) { - rc =3D -EINVAL; - goto cleanup; - } + if (name =3D=3D NULL || dir =3D=3D NULL) + return -EINVAL; =20 - if (!(pidfile =3D virPidFileBuildPath(dir, name))) { - rc =3D -ENOMEM; - goto cleanup; - } + if (!(pidfile =3D virPidFileBuildPath(dir, name))) + return -ENOMEM; =20 - rc =3D virPidFileReleasePath(pidfile, fd); - - cleanup: - VIR_FREE(pidfile); - return rc; + return virPidFileReleasePath(pidfile, fd); } =20 =20 @@ -545,8 +482,7 @@ virPidFileConstructPath(bool privileged, const char *progname, char **pidfile) { - int ret =3D -1; - char *rundir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; =20 if (privileged) { /* @@ -556,29 +492,26 @@ virPidFileConstructPath(bool privileged, if (!statedir) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No statedir specified")); - goto cleanup; + return -1; } if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0) - goto cleanup; + return -1; } else { if (!(rundir =3D virGetUserRuntimeDirectory())) - goto cleanup; + return -1; =20 if (virFileMakePathWithMode(rundir, 0700) < 0) { virReportSystemError(errno, _("Cannot create user runtime directory '= %s'"), rundir); - goto cleanup; + return -1; } =20 if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(rundir); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806915319825.2717982772791; Sat, 28 Jul 2018 12:41:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E509E3086272; Sat, 28 Jul 2018 19:41:52 +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 A12C0308BDB3; Sat, 28 Jul 2018 19:41: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 506B024F5A; Sat, 28 Jul 2018 19:41:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfkso021159 for ; Sat, 28 Jul 2018 15:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8CEB9308BDB7; Sat, 28 Jul 2018 19:41:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C35E308BDB3 for ; Sat, 28 Jul 2018 19:41:38 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) (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 C4D8A3001777 for ; Sat, 28 Jul 2018 19:41:36 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id r1-v6so5073839pgp.11 for ; Sat, 28 Jul 2018 12:41:36 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:35 -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=rg4UI661anRGaO/SUzEEqwiTp53ooLGYQeKTqk+DB1A=; b=bqrXHQqV9uA0HHzYc8u2isbhwsff9drPIkNEorVu2nncrFX6Aj+CjFWWsD2FnZpt9s Os3S4b7DqXG1lPyIc68JWm0B4Keh9LwWTQ2tR+RETauRQR1zbtTkxaBS+pn0NPDm7oBh P1kXtlbGMH30GFWJBqsqQd/thkxnplNc/ZPIlOCLPe7gk/1sVX611BTBkByTJGBYTjtQ IANFnsmheZIrsNc2OChojyOw8b0sVM3miSySmf2q51CReB4Qe39N6rLCP/Ssxxadoiqc E8pJiv0u01sCbMJB4lv/txATJtCErVg51dCUAu/3YlpJPrCWjs+ZOg2h3xIhvVaa4XM5 idwA== 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=rg4UI661anRGaO/SUzEEqwiTp53ooLGYQeKTqk+DB1A=; b=HTGzbH5v7DredwgwDsbys/nLB3ACpca+hyZ2Pj3Ofzu8hwJmjqsIofQaLD2qnLBcTa nZSeZy0pl2tXKEX9wxTCAqJdDmz1+990BFNvyT+k/Bzj9nuzQZbMbWYfw2kgEan7sBUD eqhmOTlIUQ5H2R4Mtat6WXO0NyxjB50VkmBX9hwasC9pw19F5mQFyBASFRWr6yWLpLYa iQukH1lOSW9V+/01BRdlPaBJs7SC940xRmTlA+6AX6C/WQ/IZMXfHXECpfvGJuD32dlv k983B6MEd7QtVtsV9gjdM9+JsJ3S7UQTG12cPbw5o+2Xc7VbLGA6j2kbj1QXA7dHXCwR bwxg== X-Gm-Message-State: AOUpUlErPTubIhWdZp87B/WZwgFKDZPAjoVDpKFSvjvEIdtNnvJ/pdv0 ENOuXvfvKL3pxlkAorGUNZRWKXCr X-Google-Smtp-Source: AAOMgpcoIxxGFv0/Zwk3wc2vbc9fxfIJczq7E3OhlUci3S+YxQzUu3BopCCQnnjkAL1odrUJ9uTQuw== X-Received: by 2002:a63:6c05:: with SMTP id h5-v6mr10830859pgc.367.1532806895965; Sat, 28 Jul 2018 12:41:35 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:44 +0530 Message-Id: <1532800907-29115-30-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.46]); Sat, 28 Jul 2018 19:41:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:36 +0000 (UTC) for IP:'209.85.215.193' DOMAIN:'mail-pg1-f193.google.com' HELO:'mail-pg1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.193 mail-pg1-f193.google.com 209.85.215.193 mail-pg1-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 29/32] util: process: 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:41:53 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virprocess.c | 49 ++++++++++++++++++++++++-----------------------= -- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index f92b0dc..1dd14de 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -158,7 +158,7 @@ virProcessAbort(pid_t pid) int saved_errno; int ret; int status; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (pid <=3D 0) return; @@ -199,7 +199,6 @@ virProcessAbort(pid_t pid) VIR_DEBUG("failed to reap child %lld, abandoning it", (long long) pid); =20 cleanup: - VIR_FREE(tmp); errno =3D saved_errno; } #else @@ -271,11 +270,10 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) =20 error: { - char *st =3D virProcessTranslateStatus(status); + VIR_AUTOFREE(char *) st =3D virProcessTranslateStatus(status); virReportError(VIR_ERR_INTERNAL_ERROR, _("Child process (%lld) unexpected %s"), (long long) pid, NULLSTR(st)); - VIR_FREE(st); } return -1; } @@ -475,7 +473,11 @@ virBitmapPtr virProcessGetAffinity(pid_t pid) { size_t i; +# ifdef CPU_ALLOC cpu_set_t *mask; +# else + VIR_AUTOFREE(cpu_set_t *) mask =3D NULL; +# endif size_t masklen; size_t ncpus; virBitmapPtr ret =3D NULL; @@ -504,11 +506,20 @@ virProcessGetAffinity(pid_t pid) if (sched_getaffinity(pid, masklen, mask) < 0) { virReportSystemError(errno, _("cannot get CPU affinity of process %d"), p= id); +# ifdef CPU_ALLOC goto cleanup; +# else + return ret; +# endif } =20 if (!(ret =3D virBitmapNew(ncpus))) - goto cleanup; +# ifdef CPU_ALLOC + + goto cleanup; +# else + return ret; +# endif =20 for (i =3D 0; i < ncpus; i++) { # ifdef CPU_ALLOC @@ -522,11 +533,7 @@ virProcessGetAffinity(pid_t pid) } =20 cleanup: -# ifdef CPU_ALLOC CPU_FREE(mask); -# else - VIR_FREE(mask); -# endif =20 return ret; } @@ -603,7 +610,7 @@ virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED) int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) { int ret =3D -1; - char *taskPath =3D NULL; + VIR_AUTOFREE(char *) taskPath =3D NULL; DIR *dir =3D NULL; int value; struct dirent *ent; @@ -636,7 +643,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(taskPath); if (ret < 0) VIR_FREE(*pids); return ret; @@ -648,7 +654,6 @@ int virProcessGetNamespaces(pid_t pid, int **fdlist) { int ret =3D -1; - char *nsfile =3D NULL; size_t i =3D 0; const char *ns[] =3D { "user", "ipc", "uts", "net", "pid", "mnt" }; =20 @@ -656,6 +661,7 @@ int virProcessGetNamespaces(pid_t pid, *fdlist =3D NULL; =20 for (i =3D 0; i < ARRAY_CARDINALITY(ns); i++) { + VIR_AUTOFREE(char *) nsfile =3D NULL; int fd; =20 if (virAsprintf(&nsfile, "/proc/%llu/ns/%s", @@ -671,14 +677,11 @@ int virProcessGetNamespaces(pid_t pid, =20 (*fdlist)[(*nfdlist)-1] =3D fd; } - - VIR_FREE(nsfile); } =20 ret =3D 0; =20 cleanup: - VIR_FREE(nsfile); if (ret < 0) { for (i =3D 0; i < *nfdlist; i++) VIR_FORCE_CLOSE((*fdlist)[i]); @@ -977,8 +980,8 @@ virProcessSetMaxCoreSize(pid_t pid ATTRIBUTE_UNUSED, int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { - char *filename =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) filename =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *tmp; int ret =3D -1; int len; @@ -1032,8 +1035,6 @@ int virProcessGetStartTime(pid_t pid, =20 cleanup: virStringListFree(tokens); - VIR_FREE(filename); - VIR_FREE(buf); return ret; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -1080,7 +1081,7 @@ static int virProcessNamespaceHelper(int errfd, virProcessNamespaceCallback cb, void *opaque) { - char *path; + VIR_AUTOFREE(char *) path =3D NULL; int fd =3D -1; int ret =3D -1; =20 @@ -1109,7 +1110,6 @@ static int virProcessNamespaceHelper(int errfd, ignore_value(safewrite(errfd, err->message, len)); } } - VIR_FREE(path); VIR_FORCE_CLOSE(fd); return ret; } @@ -1145,7 +1145,7 @@ virProcessRunInMountNamespace(pid_t pid, VIR_FORCE_CLOSE(errfd[1]); _exit(ret < 0 ? EXIT_CANCELED : ret); } else { - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; int status; =20 VIR_FORCE_CLOSE(errfd[1]); @@ -1159,7 +1159,6 @@ virProcessRunInMountNamespace(pid_t pid, NULLSTR(buf)); } } - VIR_FREE(buf); } =20 cleanup: @@ -1226,7 +1225,7 @@ virProcessNamespaceAvailable(unsigned int ns) int flags =3D 0; int cpid; char *childStack; - char *stack; + VIR_AUTOFREE(char *)stack =3D NULL; int stacksize =3D getpagesize() * 4; =20 if (ns & VIR_PROCESS_NAMESPACE_MNT) @@ -1251,7 +1250,7 @@ virProcessNamespaceAvailable(unsigned int ns) childStack =3D stack + stacksize; =20 cpid =3D clone(virProcessDummyChild, childStack, flags, NULL); - VIR_FREE(stack); + if (cpid < 0) { char ebuf[1024] ATTRIBUTE_UNUSED; VIR_DEBUG("clone call returned %s, container support is not enable= d", --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806910824656.0098563238776; Sat, 28 Jul 2018 12:41:50 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 12DE63001777; Sat, 28 Jul 2018 19:41:49 +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 C96F967CEF; Sat, 28 Jul 2018 19:41: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 794E41800B7D; Sat, 28 Jul 2018 19:41:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfeOh021098 for ; Sat, 28 Jul 2018 15:41:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8337716C17; Sat, 28 Jul 2018 19:41:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77FA619486 for ; Sat, 28 Jul 2018 19:41:40 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 24ED8C04F4D1 for ; Sat, 28 Jul 2018 19:41:39 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j26-v6so2875519pfi.10 for ; Sat, 28 Jul 2018 12:41:39 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:37 -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=POMIfPDvEbPPXQDkw6kZX7m4l8GbIwzz+T5Izvkh3xA=; b=UKJc1NC/1YKX0FE5qhIV0cVexXPktw9prMPRyrCMt01eN0ihNDmRkQnH7F4Yw8Pxee tL4/OYrTEUFYneQF1gCGCcZUUfbFlIxSQmuz/y22VuA3qidDfQ02+NaCgurPlDzrC0zz 2TNQpOm3bJf2ZvsLhu5TjAiWpfS92ltoHUXtj1nII5LXtKc9u0J0Muths27l4d3uGS8G 2Hq8PWuInpfiUpIw6x5LGQjnkMUzi/e/ZyB0qeSjbA0YdWdW0qaNbGLpQ+smbz60IthV ThxzAx4+AXQf4Dw0bGt1fA6dAEZbofyVOO1mFy8NGP1HuiXBolwFcLXg2UMORZpUEKm1 XzrQ== 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=POMIfPDvEbPPXQDkw6kZX7m4l8GbIwzz+T5Izvkh3xA=; b=DiSTWZLRlUpm6TtHIicIgmKU3T7FOTrixPvtQ5DPaHY4xmosBD6Nea+AEIKPRXBqmX ZPtet8PRdWOq1TDkbPBDOhq2CzM73AooRggT+2PlvzVDs8SbavYnwc/RomMsjFMne64N 8kqtA9/Rl2yg6JUsA8NyxFFVPQjhQJxApXV52+Fyh2/O137eO2F57cMYZsHNDz6XE9Mr mL16cATa8KQ6P9BWx0OJpDuCL9bTVPPQ2vKWXINd5BWw3oWlQXDrdfzoX5A7B4aJpv0I CXHR7UlfSWwpGKDFskawbmEbS9Qb0Mq6UTkc96AlgkIWHa4eRsXphE0sCnAjz/L9fpTb 94fQ== X-Gm-Message-State: AOUpUlH0a57rxbZa7iDKsL3+877+9NqgkkO8TDXPx+eVpBtwJnDqTOI3 w+oJOiYNnpgCFNKFvFUOLXZsv1kS X-Google-Smtp-Source: AAOMgpfOHI3+fx1c7nM2IPpqqNzaBaPFao5o7gS1SyN0Zbb98dNjJJmxKwSIkQKYBYqC04tHFb5CXQ== X-Received: by 2002:a63:c44a:: with SMTP id m10-v6mr10746652pgg.416.1532806898301; Sat, 28 Jul 2018 12:41:38 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:45 +0530 Message-Id: <1532800907-29115-31-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.31]); Sat, 28 Jul 2018 19:41:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 28 Jul 2018 19:41:39 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 30/32] util: process: use VIR_AUTOPTR for aggregate 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 19:41:49 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virprocess.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 1dd14de..b51d899 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -982,16 +982,15 @@ int virProcessGetStartTime(pid_t pid, { VIR_AUTOFREE(char *) filename =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; char *tmp; - int ret =3D -1; int len; - char **tokens =3D NULL; =20 if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0) return -1; =20 if ((len =3D virFileReadAll(filename, 1024, &buf)) < 0) - goto cleanup; + return -1; =20 /* start time is the token at index 19 after the '(process name)' entr= y - since only this * field can contain the ')' character, search backwards for this to a= void malicious @@ -1002,14 +1001,14 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } tmp +=3D 2; /* skip ') ' */ if ((tmp - buf) >=3D len) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 tokens =3D virStringSplit(tmp, " ", 0); @@ -1018,7 +1017,7 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 if (virStrToLong_ull(tokens[19], @@ -1028,14 +1027,10 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse start time %s in %s"), tokens[19], filename); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virStringListFree(tokens); - return ret; + return 0; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int virProcessGetStartTime(pid_t pid, --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 14:51:54 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; 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 1532806912260283.3182812122974; Sat, 28 Jul 2018 12:41:52 -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 8BE63307D86C; Sat, 28 Jul 2018 19:41:50 +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 571A760175; Sat, 28 Jul 2018 19:41: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 1FBCF1800B77; Sat, 28 Jul 2018 19:41:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJffGW021113 for ; Sat, 28 Jul 2018 15:41:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDA163083320; Sat, 28 Jul 2018 19:41:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6BE83001A6A for ; Sat, 28 Jul 2018 19:41:41 +0000 (UTC) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 E882B3086267 for ; Sat, 28 Jul 2018 19:41:40 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id u24-v6so2874211pfn.13 for ; Sat, 28 Jul 2018 12:41:40 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:39 -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=p2Hiuq1eALjtD0yaJTBq5ZX8g5VmXX/7/YzApzVKh14=; b=KM2sJnRSAD5D39Ul67MQSj4yT+c5dLuaCQTTJj0IeUeVbTqqQ7GnSac4uuvQfBOiKL k0yXZ/ilYjmnv7wQ2dse64FMXes0uyEUOejeLeQrUO0kD2ETi/3osbzKNGH/MIKs84bW aQIq7F7Q7JV1a9pQEDDL/i1BxbFp8lgiSY45oroYJ5F/F+ka883kAqYs5l8ycMd+oAYr Y26i++TCQUzQrSU4St7CN9uUrf3djycxGr+36/Yptd1imMFilJeY4TecNTKUr1HmvA0r +sDfsGkl2hAvjvNwfEPITgMMuIcAUBvKeu076E0j7hNKQs4hl/XWQX4KUdFvKCW8DIZs Sq+Q== 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=p2Hiuq1eALjtD0yaJTBq5ZX8g5VmXX/7/YzApzVKh14=; b=bD7ooT5biVt3Etj2dYrWajjrBf/AXZVLyarNpV49PVTKtFHF/KftJbcGcYxoZZAOg5 zXouj8GYZW0ErqZeJoyaT1xHkhErYPAPFyg8Xppn/321UBEh7xpXShuRo60Sf9/Wv6jK w9BJr6en2y2C06sozK6i1rZfYQqRmwrAso1d+OuSfDi8LoG6S8A/ZjGo3Cp/4Hly4hwJ hZbX188e8pKyTTJw8tZXZaVlGozpCUsy9piDQTCoADr+eTDiA5P7o0HO+KUIWA0H/fDt kejQ96X6EN5ZdBOPa2cZdNi8iv2U/ALr3FSs52Wz2t3cO9AlgQszOBjJfxJsuRWd6fJ8 9mQg== X-Gm-Message-State: AOUpUlGlMuHzhF41QRpCMewgNwN9kPRs3IVHCzGkOML8PE40JiDDipcq Jf/fkNHLHh73NJVdafLqubGqz7g2 X-Google-Smtp-Source: AAOMgpdAFCtdm0StHJ+fO1iPCmxeZ5/wr4XAdNL7TBxTgkHhTTkDANsmIcPaFvyRRDaczV6H0kY9tQ== X-Received: by 2002:a63:a042:: with SMTP id u2-v6mr10495350pgn.80.1532806900227; Sat, 28 Jul 2018 12:41:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:46 +0530 Message-Id: <1532800907-29115-32-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.49]); Sat, 28 Jul 2018 19:41:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:41:41 +0000 (UTC) for IP:'209.85.210.174' DOMAIN:'mail-pf1-f174.google.com' HELO:'mail-pf1-f174.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.210.174 mail-pf1-f174.google.com 209.85.210.174 mail-pf1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 31/32] util: qemu: 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.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.48]); Sat, 28 Jul 2018 19:41:51 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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 --- src/util/virqemu.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 30b8dc1..4089b8e 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -85,29 +85,22 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *ke= y, virBufferPtr buf) { virJSONValuePtr member; - char *prefix =3D NULL; size_t i; - int ret =3D 0; =20 for (i =3D 0; i < virJSONValueArraySize(array); i++) { + VIR_AUTOFREE(char *) prefix =3D NULL; member =3D virJSONValueArrayGet((virJSONValuePtr) array, i); =20 if (virAsprintf(&prefix, "%s.%zu", key, i) < 0) - goto cleanup; + return 0; =20 if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) - goto cleanup; - - VIR_FREE(prefix); + return 0; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(prefix); - return ret; + return 0; } =20 =20 @@ -118,23 +111,18 @@ virQEMUBuildCommandLineJSONIterate(const char *key, void *opaque) { struct virQEMUCommandLineJSONIteratorData *data =3D opaque; - char *tmpkey =3D NULL; - int ret =3D -1; =20 if (data->prefix) { + VIR_AUTOFREE(char *) tmpkey =3D NULL; if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0) return -1; =20 - ret =3D virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->bu= f, + return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, data->arrayFunc, false); - - VIR_FREE(tmpkey); } else { - ret =3D virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, + return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, data->arrayFunc, false); } - - 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 From nobody Fri May 3 14:51:54 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; 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 1532806930834487.42030879576953; Sat, 28 Jul 2018 12:42:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 676C15F73F; Sat, 28 Jul 2018 19:42:01 +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 1429210842A0; Sat, 28 Jul 2018 19:42:01 +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 BF7AA1800B75; Sat, 28 Jul 2018 19:42:00 +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 w6SJftYZ021273 for ; Sat, 28 Jul 2018 15:41:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id F29BF60172; Sat, 28 Jul 2018 19:41:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB9D560170 for ; Sat, 28 Jul 2018 19:41:44 +0000 (UTC) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 1A34983F44 for ; Sat, 28 Jul 2018 19:41:43 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id y4-v6so5071693pgp.9 for ; Sat, 28 Jul 2018 12:41:43 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:41 -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=3IDdh8E10qDObB3pQuUH/CXOdvHqWjVrzsBp+Aw5WOg=; b=nBkFGqtrgPlNgf/772GIVGfajznIrxCJQAa49rWbMTM6r8qsY1tbtHEzvoaWcIBOyu K0m3HjUzYeg36+eiinIL5mRc+iGqwVtkd99aUpmly73i8tP3x/xDbO0EYMK3r9aRcc7o iv2x29lTHH/G/bByQkaiOB4SsxkMfSdLSU+A3gogsNsbeHeJd2Sjld+QNHYfYl46G0pi ucBJ1ypqzymFllrPOZ4gon8072VOwnLwrUdnIs5FWEyZq4z/dIba+nEdH8iI+dSQMaJ4 zkTWX7Xux8kwKZftZoC+L2LIN8S8zeLfHHXVvdAmLBwjHNXS14tgJbNfC0c7QW1/bF3q QC5w== 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=3IDdh8E10qDObB3pQuUH/CXOdvHqWjVrzsBp+Aw5WOg=; b=kGWZ076RZbjWe2Y1ZdA1ro4VtcvszjsWR8GzDfTW32ST19bXMooyYfiPahSF5TisuF DD91AlETFhG1wB/uC+GQ6Cd1U3Rf+Ov7o/NcY0++FSJoYznZfRtJvGNIjh8KB8RZXurG UXCtDLS2qaCRTsq/m9JsLHiciJGuTqjpmfKmeel6MZ0yrlmv3hOr7HXSC/IaFzuCmPKp uuPrVqWhM1/7jo2i+YlUhQ1jRilhXqm9qyiwgzR2DCkAtgzQv0nyth7W7Bo34ykSbOX5 HCZZcdJu5o5sYiv51F7RWHohpNNCy/WF8jfVYJAXlET81ypCDa5YsEOWUieU3ymYpg2u nbjg== X-Gm-Message-State: AOUpUlFmQ77LbCjhAZPjo4bnnVt5SMcTt9dTZ5eHstIoLV9MH/jMmlIr bW3pxLvdPd3pbKnVNr15CXj1U6f8 X-Google-Smtp-Source: AAOMgpen/cmo0ptkSwpwjo/nUpEdRkKits35g34h//My2zh1ZmcWRhd6gLy94ytLB3DZMQpmNbgA+Q== X-Received: by 2002:a65:46ca:: with SMTP id n10-v6mr10837107pgr.345.1532806902378; Sat, 28 Jul 2018 12:41:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:47 +0530 Message-Id: <1532800907-29115-33-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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.27]); Sat, 28 Jul 2018 19:41:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 28 Jul 2018 19:41:43 +0000 (UTC) for IP:'209.85.215.178' DOMAIN:'mail-pg1-f178.google.com' HELO:'mail-pg1-f178.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.178 mail-pg1-f178.google.com 209.85.215.178 mail-pg1-f178.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 32/32] util: qemu: use VIR_AUTOPTR for aggregate 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 28 Jul 2018 19:42:02 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virqemu.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 4089b8e..cb42d38 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -56,7 +56,7 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, { ssize_t pos =3D -1; ssize_t end; - virBitmapPtr bitmap =3D NULL; + VIR_AUTOPTR(virBitmap) bitmap =3D NULL; =20 if (virJSONValueGetArrayAsBitmap(array, &bitmap) < 0) return -1; @@ -73,8 +73,6 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, } } =20 - virBitmapFree(bitmap); - return 0; } =20 @@ -267,21 +265,19 @@ virQEMUBuildObjectCommandlineFromJSON(virBufferPtr bu= f, char * virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *ret =3D NULL; + VIR_AUTOPTR(virBuffer) buf =3D NULL; =20 - if (virQEMUBuildCommandLineJSON(srcdef, &buf, + if (VIR_ALLOC(buf) < 0) + return NULL; + + if (virQEMUBuildCommandLineJSON(srcdef, buf, virQEMUBuildCommandLineJSONArrayNumber= ed) < 0) - goto cleanup; + return NULL; =20 - if (virBufferCheckError(&buf) < 0) - goto cleanup; + if (virBufferCheckError(buf) < 0) + return NULL; =20 - ret =3D virBufferContentAndReset(&buf); - - cleanup: - virBufferFreeAndReset(&buf); - return ret; + return virBufferContentAndReset(buf); } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list