From nobody Mon Feb 9 09:51:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174953758981.4744100117653; Sat, 21 Jul 2018 05:09:13 -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 F1E9A30832E1; Sat, 21 Jul 2018 12:09:10 +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 BCBE52016207; Sat, 21 Jul 2018 12:09:10 +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 76B0B4EE1F; Sat, 21 Jul 2018 12:09:10 +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 w6LC8DNc016376 for ; Sat, 21 Jul 2018 08:08:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2813308BDB4; Sat, 21 Jul 2018 12:08:13 +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 D7740308BDB3 for ; Sat, 21 Jul 2018 12:08:13 +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 A55AE356F0 for ; Sat, 21 Jul 2018 12:08:02 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id 6-v6so6311125plb.0 for ; Sat, 21 Jul 2018 05:08:02 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08: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=YlnOWIenqsvgSYi5U/sHoybu4wG23RbKR00iHdAAKiw=; b=nbdqHTH4aSsgct9ydLNbxlSo8scubohNPz+kuJ+RUkor2OYtrAHwmvUmsef3H50Cyx 80W8c1kp2fnkSXezUdrbc5MFVBSq6OEgk8RcrUmbA7+EYryCIZaVBU++QQN+RfXC1itm RHxpbWgSVqciGkgiXUpGfZWsbyL9I+M53IjuY3ryU3yEsWl7FPL4+IZnN5dLegItn1zC KLbTPDMdAVRkqpvH8eAZWidqSsOh6UmPUZ2kMjqBzJxUwoKWTq9UtkeLWEKKCvIbiunH JpkQQuNtWlHJUFWK1QK+3rHrgsulM+MU2FUT4zzydSakiFW8VhjS+y13Ezs+CrjvcxUG bSvA== 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=YlnOWIenqsvgSYi5U/sHoybu4wG23RbKR00iHdAAKiw=; b=uGPMLhPpQ4Qug6axQptyDqi9+DdWJsZm0NRxaU0vPKqWguvPPkQMXPoOA0euAMPeg7 AEi97lNgC9vGYWS6ZcmzCrEGKzzOc5k94O2Vfghci5AdD9CCSmprDtoPwj0p3JcAE95j +A5QD0PsaNcicUJzmOmQIc7VsOr68N4Fk/ozyydidAzWeF1H/KJHgp0QCuv2n1C0dzxm VpkJ/Aa2pEDWIKKf4qPlthTSmr3jaKs/kkzu0W/Ld0MwZ0vRCIgQv1cjFyJzBO27aAu3 TPDHBdAVGtpRmlnD/PZ+dmF98ki8KkRu90THsq7SN3u+V8HY66uQKnK/mG3UL9afZJsY I7AQ== X-Gm-Message-State: AOUpUlEemOZwbLeTZJfa+znyfFf1pqnpoqAPFzYiYeG/WbR0RGBU0A55 6tb7g74SlZ9yqWg2OM6Sep+Th15e X-Google-Smtp-Source: AAOMgpeHMmGdeOk+VnU6rxPpSxm8ZoLPs7MIwyJeJXem7ii8I2XThLc3pEITI8oloihEJ1Mkk12yJA== X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr5722656plc.11.1532174881928; Sat, 21 Jul 2018 05:08:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:48 +0530 Message-Id: <1532174832-21644-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-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, 21 Jul 2018 12:08:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:08:02 +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: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 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.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 16/40] 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.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.44]); Sat, 21 Jul 2018 12:09: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" 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