From: Peter Krempa Date: Thu, 5 Mar 2020 08:33:55 +0000 (+0100) Subject: testQemuMonitorJSONqemuMonitorJSONGetTargetArch: Fix uninitialized use of 'arch' X-Git-Tag: v6.2.0-rc1~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a2390f6409ca1ed0da10c6184258f4a3d3a0135;p=thirdparty%2Flibvirt.git testQemuMonitorJSONqemuMonitorJSONGetTargetArch: Fix uninitialized use of 'arch' Refactor the cleanup control flow and use g_autofree for 'arch' so that it's mandated that it's initialized. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index e9f95e317d..c7049bcdf0 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2162,8 +2162,7 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *opaque) { const testGenericData *data = opaque; virDomainXMLOptionPtr xmlopt = data->xmlopt; - int ret = -1; - char *arch; + g_autofree char *arch = NULL; g_autoptr(qemuMonitorTest) test = NULL; if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -2176,22 +2175,19 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *opaque) " }," " \"id\": \"libvirt-21\"" "}") < 0) - goto cleanup; + return -1; if (!(arch = qemuMonitorJSONGetTargetArch(qemuMonitorTestGetMonitor(test)))) - goto cleanup; + return -1; if (STRNEQ(arch, "x86_64")) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected architecture %s, expecting x86_64", arch); - goto cleanup; + return -1; } - ret = 0; - cleanup: - VIR_FREE(arch); - return ret; + return 0; } static int