]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
openvz: refactor openvzVEGetStringParam
authorJán Tomko <jtomko@redhat.com>
Mon, 13 Dec 2021 18:28:27 +0000 (19:28 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 14 Dec 2021 15:41:06 +0000 (16:41 +0100)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/openvz/openvz_util.c

index d14254c2316b2e85f87a6da99fa5a724653ff98d..9419ce122c3ba50ba96b868df20db1bc2fc55d32 100644 (file)
@@ -58,27 +58,22 @@ char*
 openvzVEGetStringParam(virDomainPtr domain, const char* param)
 {
     int len;
-    char *output = NULL;
+    g_autofree char *output = NULL;
 
-    virCommand *cmd = virCommandNewArgList(VZLIST,
-                                             "-o",
-                                             param,
-                                             domain->name,
-                                             "-H", NULL);
+    g_autoptr(virCommand) cmd = virCommandNewArgList(VZLIST,
+                                                     "-o",
+                                                     param,
+                                                     domain->name,
+                                                     "-H", NULL);
 
     virCommandSetOutputBuffer(cmd, &output);
-    if (virCommandRun(cmd, NULL) < 0) {
-        VIR_FREE(output);
-        /* virCommandRun sets the virError */
-        goto cleanup;
-    }
+    if (virCommandRun(cmd, NULL) < 0)
+        return NULL;
 
     /* delete trailing newline */
     len = strlen(output);
     if (len && output[len - 1] == '\n')
         output[len - 1] = '\0';
 
- cleanup:
-    virCommandFree(cmd);
-    return output;
+    return g_steal_pointer(&output);
 }