[PATCH 1/5] virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/conf/virnetworkportdef.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index b58e2ccae0..a4cffea8b6 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -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;
 }


-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux