From: Matt Coleman Date: Thu, 21 Jan 2021 18:51:25 +0000 (-0500) Subject: hyperv: use GLib auto-cleanup in hypervMsvmVSMSAddResourceSettings and hypervMsvmVSMS... X-Git-Tag: v7.1.0-rc1~456 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ddeafe0835ef673be493f52e6e6020e7b13b16c;p=thirdparty%2Flibvirt.git hyperv: use GLib auto-cleanup in hypervMsvmVSMSAddResourceSettings and hypervMsvmVSMSModifyResourceSettings Fixes a memory leak when hypervCreateInvokeParamsList() fails. Signed-off-by: Matt Coleman Reviewed-by: Laine Stump --- diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index bd62174739..ed0091ba06 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1545,18 +1545,19 @@ hypervMsvmVSMSAddResourceSettings(virDomainPtr domain, hypervWmiClassInfoPtr wmiInfo, WsXmlDocH *response) { - int result = -1; hypervPrivate *priv = domain->conn->privateData; char uuid_string[VIR_UUID_STRING_BUFLEN]; - Msvm_VirtualSystemSettingData *vssd = NULL; - GHashTable *resourceSettings = *resourceSettingsPtr; + g_autoptr(Msvm_VirtualSystemSettingData) vssd = NULL; + g_autoptr(GHashTable) resourceSettings = *resourceSettingsPtr; g_autoptr(hypervInvokeParamsList) params = NULL; g_auto(virBuffer) eprQuery = VIR_BUFFER_INITIALIZER; + *resourceSettingsPtr = NULL; + virUUIDFormat(domain->uuid, uuid_string); if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, uuid_string, &vssd) < 0) - goto cleanup; + return -1; virBufferEscapeSQL(&eprQuery, MSVM_VIRTUALSYSTEMSETTINGDATA_WQL_SELECT "WHERE InstanceID='%s'", @@ -1567,27 +1568,21 @@ hypervMsvmVSMSAddResourceSettings(virDomainPtr domain, Msvm_VirtualSystemManagementService_WmiInfo); if (!params) - goto cleanup; + return -1; if (hypervAddEprParam(params, "AffectedConfiguration", &eprQuery, Msvm_VirtualSystemSettingData_WmiInfo) < 0) - goto cleanup; + return -1; if (hypervAddEmbeddedParam(params, "ResourceSettings", &resourceSettings, wmiInfo) < 0) { hypervFreeEmbeddedParam(resourceSettings); - goto cleanup; + return -1; } if (hypervInvokeMethod(priv, ¶ms, response) < 0) - goto cleanup; - - result = 0; - - cleanup: - hypervFreeObject((hypervObject *)vssd); - *resourceSettingsPtr = NULL; + return -1; - return result; + return 0; } @@ -1596,29 +1591,25 @@ hypervMsvmVSMSModifyResourceSettings(hypervPrivate *priv, GHashTable **resourceSettingsPtr, hypervWmiClassInfoPtr wmiInfo) { - int result = -1; - GHashTable *resourceSettings = *resourceSettingsPtr; + g_autoptr(GHashTable) resourceSettings = *resourceSettingsPtr; g_autoptr(hypervInvokeParamsList) params = NULL; + *resourceSettingsPtr = NULL; + params = hypervCreateInvokeParamsList("ModifyResourceSettings", MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, Msvm_VirtualSystemManagementService_WmiInfo); if (!params) - goto cleanup; + return -1; if (hypervAddEmbeddedParam(params, "ResourceSettings", &resourceSettings, wmiInfo) < 0) { hypervFreeEmbeddedParam(resourceSettings); - goto cleanup; + return -1; } if (hypervInvokeMethod(priv, ¶ms, NULL) < 0) - goto cleanup; - - result = 0; - - cleanup: - *resourceSettingsPtr = NULL; + return -1; - return result; + return 0; }