]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh-domain.c: use g_auto* in cmdDetachDevice()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 4 Jan 2021 12:54:37 +0000 (09:54 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 1 Mar 2021 15:25:33 +0000 (12:25 -0300)
Use g_auto* pointers to avoid the need of a cleanup label. The
type of the pointer 'virDomainPtr dom' was changed to its alias
'virshDomainPtr' to allow the use of g_autoptr().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
tools/virsh-domain.c

index cac2d33a293202f3d53b9d9a336529e6ca092d05..d24654c7c43f0306f6f2edf4b30671aa84328085 100644 (file)
@@ -11948,11 +11948,10 @@ static const vshCmdOptDef opts_detach_device[] = {
 static bool
 cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
 {
-    virDomainPtr dom = NULL;
+    g_autoptr(virshDomain) dom = NULL;
     const char *from = NULL;
-    char *buffer = NULL;
+    g_autofree char *buffer = NULL;
     int ret;
-    bool funcRet = false;
     bool current = vshCommandOptBool(cmd, "current");
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
@@ -11977,11 +11976,11 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_AFFECT_LIVE;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
-        goto cleanup;
+        return false;
 
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
         vshReportError(ctl);
-        goto cleanup;
+        return false;
     }
 
     if (flags != 0 || current)
@@ -11991,16 +11990,11 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
 
     if (ret < 0) {
         vshError(ctl, _("Failed to detach device from %s"), from);
-        goto cleanup;
+        return false;
     }
 
     vshPrintExtra(ctl, "%s", _("Device detached successfully\n"));
-    funcRet = true;
-
- cleanup:
-    VIR_FREE(buffer);
-    virshDomainFree(dom);
-    return funcRet;
+    return true;
 }