[libvirt PATCH 4/6] util: virNetDevBandwidthClear: use g_auto

Ján Tomko jtomko at redhat.com
Mon Jan 17 17:02:31 UTC 2022


Separate the two uses of 'cmd' to avoid mixing manual and automatic
cleanup.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/util/virnetdevbandwidth.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c
index fe354696f2..cb9a22a369 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -416,27 +416,24 @@ virNetDevBandwidthClear(const char *ifname)
 {
     int ret = 0;
     int dummy; /* for ignoring the exit status */
-    virCommand *cmd = NULL;
+    g_autoptr(virCommand) rootcmd = NULL;
+    g_autoptr(virCommand) ingresscmd = NULL;
 
     if (!ifname)
        return 0;
 
-    cmd = virCommandNew(TC);
-    virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "root", NULL);
+    rootcmd = virCommandNew(TC);
+    virCommandAddArgList(rootcmd, "qdisc", "del", "dev", ifname, "root", NULL);
 
-    if (virCommandRun(cmd, &dummy) < 0)
+    if (virCommandRun(rootcmd, &dummy) < 0)
         ret = -1;
 
-    virCommandFree(cmd);
+    ingresscmd = virCommandNew(TC);
+    virCommandAddArgList(ingresscmd, "qdisc",  "del", "dev", ifname, "ingress", NULL);
 
-    cmd = virCommandNew(TC);
-    virCommandAddArgList(cmd, "qdisc",  "del", "dev", ifname, "ingress", NULL);
-
-    if (virCommandRun(cmd, &dummy) < 0)
+    if (virCommandRun(ingresscmd, &dummy) < 0)
         ret = -1;
 
-    virCommandFree(cmd);
-
     return ret;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list