]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring...
authorPeter Krempa <pkrempa@redhat.com>
Thu, 5 Mar 2020 08:20:48 +0000 (09:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 5 Mar 2020 15:21:47 +0000 (16:21 +0100)
Use 'g_autofree' to clean both 'path' and 'xml' which mandates
initialization and get rid of the 'cleanup' label and 'ret variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/virnetworkportdef.c

index b58e2ccae0c3309e402c216665a2d60cc25bd85b..a4cffea8b6038050a02945af34b4c430835ceecc 100644 (file)
@@ -444,29 +444,24 @@ virNetworkPortDefSaveStatus(virNetworkPortDef *def,
                             const char *dir)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    char *path;
-    char *xml = NULL;
-    int ret = -1;
+    g_autofree char *path = NULL;
+    g_autofree char *xml = NULL;
 
     virUUIDFormat(def->uuid, uuidstr);
 
     if (virFileMakePath(dir) < 0)
-        goto cleanup;
+        return -1;
 
     if (!(path = virNetworkPortDefConfigFile(dir, uuidstr)))
-        goto cleanup;
+        return -1;
 
     if (!(xml = virNetworkPortDefFormat(def)))
-        goto cleanup;
+        return -1;
 
     if (virXMLSaveFile(path, uuidstr, "net-port-create", xml) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    VIR_FREE(xml);
-    VIR_FREE(path);
-    return ret;
+    return 0;
 }