From: Peter Krempa Date: Thu, 5 Mar 2020 08:20:48 +0000 (+0100) Subject: virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring... X-Git-Tag: v6.2.0-rc1~271 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78ead2529bfd3856a1d0a3e8968f80d43142d0cf;p=thirdparty%2Flibvirt.git virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring cleanup 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 Reviewed-by: Ján Tomko --- 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; }