[libvirt PATCH 01/20] openvz: refactor openvzExtractVersionInfo

Ján Tomko jtomko at redhat.com
Mon Dec 13 18:42:53 UTC 2021


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/openvz/openvz_conf.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 4fb18c03ee..53170a720b 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -66,11 +66,10 @@ strtoI(const char *str)
 static int
 openvzExtractVersionInfo(const char *cmdstr, int *retversion)
 {
-    int ret = -1;
     unsigned long version;
-    char *help = NULL;
+    g_autofree char *help = NULL;
     char *tmp;
-    virCommand *cmd = virCommandNewArgList(cmdstr, "--help", NULL);
+    g_autoptr(virCommand) cmd = virCommandNewArgList(cmdstr, "--help", NULL);
 
     if (retversion)
         *retversion = 0;
@@ -79,27 +78,21 @@ openvzExtractVersionInfo(const char *cmdstr, int *retversion)
     virCommandSetOutputBuffer(cmd, &help);
 
     if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     tmp = help;
 
     /* expected format: vzctl version <major>.<minor>.<micro> */
     if ((tmp = STRSKIP(tmp, "vzctl version ")) == NULL)
-        goto cleanup;
+        return -1;
 
     if (virParseVersionString(tmp, &version, true) < 0)
-        goto cleanup;
+        return -1;
 
     if (retversion)
         *retversion = version;
 
-    ret = 0;
-
- cleanup:
-    virCommandFree(cmd);
-    VIR_FREE(help);
-
-    return ret;
+    return 0;
 }
 
 int openvzExtractVersion(struct openvz_driver *driver)
-- 
2.31.1




More information about the libvir-list mailing list