]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: refactor virBhyveProbeGrubCaps
authorJán Tomko <jtomko@redhat.com>
Fri, 10 Dec 2021 16:39:57 +0000 (17:39 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 13 Dec 2021 17:20:45 +0000 (18:20 +0100)
Use g_auto and remove the 'ret' variable, as well as the cleanup label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/bhyve/bhyve_capabilities.c

index 5a0c6c2b773c1fe5ceeae1c8f6790ca9dcff1be0..ed0df35518adedb84dbc7fcd6d1b56f212aa0639 100644 (file)
@@ -168,35 +168,27 @@ virBhyveDomainCapsBuild(struct _bhyveConn *conn,
 int
 virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps)
 {
-    char *binary, *help;
-    virCommand *cmd;
-    int ret, exit;
+    g_autofree char *binary = NULL;
+    g_autofree char *help = NULL;
+    g_autoptr(virCommand) cmd = NULL;
+    int exit;
 
-    ret = 0;
     *caps = 0;
-    cmd = NULL;
-    help = NULL;
 
     binary = virFindFileInPath("grub-bhyve");
-    if (binary == NULL)
-        goto out;
+    if (!binary)
+        return 0;
 
     cmd = virCommandNew(binary);
     virCommandAddArg(cmd, "--help");
     virCommandSetOutputBuffer(cmd, &help);
-    if (virCommandRun(cmd, &exit) < 0) {
-        ret = -1;
-        goto out;
-    }
+    if (virCommandRun(cmd, &exit) < 0)
+        return -1;
 
     if (strstr(help, "--cons-dev") != NULL)
         *caps |= BHYVE_GRUB_CAP_CONSDEV;
 
- out:
-    VIR_FREE(help);
-    virCommandFree(cmd);
-    VIR_FREE(binary);
-    return ret;
+    return 0;
 }
 
 static int