From nobody Tue May 13 11:12:37 2025 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 1532639177640804.4815772936372; Thu, 26 Jul 2018 14:06:17 -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 9DFC1C057FA8; Thu, 26 Jul 2018 21:06: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 5F66260181; Thu, 26 Jul 2018 21:06: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 088AE1800B7E; Thu, 26 Jul 2018 21:06: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 w6QL5FB1024818 for ; Thu, 26 Jul 2018 17:05:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6FC81CE220; Thu, 26 Jul 2018 21:05:15 +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 67B8ECE20B for ; Thu, 26 Jul 2018 21:05:11 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 EEFDFC057F85 for ; Thu, 26 Jul 2018 21:05:09 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id k3-v6so1886675pgq.5 for ; Thu, 26 Jul 2018 14:05:09 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.05.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:08 -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=ml9xGzAqmy9FcNeRbANrmZkm9A2iUOyWZ1Igh7JZeg8=; b=QdJWoZvjteddbopuiQHn593GIWxKMNukao/sOFivdtPX4DSOJXdnlAc4IUHvuTY3iR FB0QbX2VV6D04CzXobkJ5aF39WqtqaBAZT1EVsyYBUSvCH/ww1MdbAaI7z8FXw1RJ2jB gzZHD/Gvm/6vvzHxaBel/20/Gzn0g+hnBZp6NQR5IcsNehOjHAB+C6ZNA75tcZ74Cr3c 4didq/pLmQjsoF0dDnaDjn60EKG7S9w2R+jTs/M0zr0KcON89kcExLHy+NIQs6LNLbYw +Ow2mmm2NCqCkJvraYNlVxtTgh2+jwhLB2nI522c2kEG7fGvQt2XwhwH9X7b5X0aVBc7 efew== 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=ml9xGzAqmy9FcNeRbANrmZkm9A2iUOyWZ1Igh7JZeg8=; b=WmHwh0r9cRvn+bn1w5BaUlVNxWNSj4pnwvN7zBmMn54sU1YU8Yuv4lZj//XSB552uQ tOMToPz85NWEH9ysV+IjVs5cka0yGGIQBcduVyj48XhGaoKKnUCbhkMB9ly/YCZ/grCQ UV7VQwIJl4c3AfheqJisHE5mZybQm+zQQi/XeQs264h/L2fj9Ryp2kXUIGy3Xp2/gPJQ 7Qy24be/766WIOn3Ag0zqEZTdlg0oxm5a+GbOu1qJKB6c7zkAB/lcuYeg5D8lHkkEtee yNolaF/yoeHPHGhCCzouc7O6UzO58ovXoWjfeY/w1gIA+MzBcAnylITSUO4h5D2BvEey dKqw== X-Gm-Message-State: AOUpUlHQn1/cNiGqCn0h/F+QusJsiufnP+UUv9aLIwSQlgHIiOfmXK2Q wTNMw1Ayx0GlXc+eJbFCBN15xfWx X-Google-Smtp-Source: AAOMgpf6gWIQshuoXKSQws2/ClzCcImq5zBQT4xvSgZDHXGMLMHQlgKfF0Yq22H1CvvZF9eK64F+Pg== X-Received: by 2002:a62:3b03:: with SMTP id i3-v6mr3642820pfa.197.1532639109180; Thu, 26 Jul 2018 14:05:09 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:17 +0530 Message-Id: <1532447562-24010-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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]); Thu, 26 Jul 2018 21:05:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 26 Jul 2018 21:05:10 +0000 (UTC) for IP:'209.85.215.177' DOMAIN:'mail-pg1-f177.google.com' HELO:'mail-pg1-f177.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.215.177 mail-pg1-f177.google.com 209.85.215.177 mail-pg1-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 16/41] util: firewall: 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.32]); Thu, 26 Jul 2018 21:06:16 +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/virfirewall.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index b4a4d06..c786d76 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -119,14 +119,13 @@ virFirewallCheckUpdateLock(bool *lockflag, const char *const*args) { int status; /* Ignore failed commands without logging them */ - virCommandPtr cmd =3D virCommandNewArgs(args); + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgs(args); if (virCommandRun(cmd, &status) < 0 || status) { VIR_INFO("locking not supported by %s", args[0]); } else { VIR_INFO("using locking for %s", args[0]); *lockflag =3D true; } - virCommandFree(cmd); } =20 static void @@ -673,16 +672,15 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, { size_t i; const char *bin =3D virFirewallLayerCommandTypeToString(rule->layer); - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; VIR_AUTOFREE(char *) error =3D NULL; =20 if (!bin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown firewall layer %d"), rule->layer); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(bin, NULL); @@ -694,7 +692,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, virCommandSetErrorBuffer(cmd, &error); =20 if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; =20 if (status !=3D 0) { if (ignoreErrors) { @@ -705,14 +703,11 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, _("Failed to apply firewall rules %s: %s"), NULLSTR(args), NULLSTR(error)); VIR_FREE(*output); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -805,8 +800,7 @@ virFirewallApplyRule(virFirewallPtr firewall, { VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOFREE(char *) str =3D virFirewallRuleToString(rule); - char **lines =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virString) lines =3D NULL; VIR_INFO("Applying rule '%s'", NULLSTR(str)); =20 if (rule->ignoreErrors) @@ -831,28 +825,25 @@ virFirewallApplyRule(virFirewallPtr firewall, =20 if (rule->queryCB && output) { if (!(lines =3D virStringSplit(output, "\n", -1))) - goto cleanup; + return -1; =20 VIR_DEBUG("Invoking query %p with '%s'", rule->queryCB, output); if (rule->queryCB(firewall, (const char *const *)lines, rule->quer= yOpaque) < 0) - goto cleanup; + return -1; =20 if (firewall->err =3D=3D ENOMEM) { virReportOOMError(); - goto cleanup; + return -1; } if (firewall->err) { virReportSystemError(firewall->err, "%s", _("Unable to create rule")); - goto cleanup; + return -1; } =20 } =20 - ret =3D 0; - cleanup: - virStringListFree(lines); - return ret; + return 0; } =20 static int @@ -926,7 +917,7 @@ virFirewallApply(virFirewallPtr firewall) if (virFirewallApplyGroup(firewall, i) < 0) { VIR_DEBUG("Rolling back groups up to %zu for %p", i, firewall); size_t first =3D i; - virErrorPtr saved_error =3D virSaveLastError(); + VIR_AUTOPTR(virError) saved_error =3D virSaveLastError(); =20 /* * Look at any inheritance markers to figure out @@ -947,7 +938,6 @@ virFirewallApply(virFirewallPtr firewall) } =20 virSetError(saved_error); - virFreeError(saved_error); VIR_DEBUG("Done rolling back groups for %p", firewall); goto cleanup; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list