mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
esx: fix memory leak by switching to g_autofree
volumeName was defined at the top of the function, then a new string was assigned to it each time through a loop, but after the first iteration of the loop, the previous string wasn't freed before allocating a new string the next time. By reducing the scope of volumeName to be just the loop, and making it g_autofree, we eliminate the leak. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
22a370d8b1
commit
d79a6e2c8c
@ -728,7 +728,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
||||||
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
||||||
size_t length;
|
size_t length;
|
||||||
char *volumeName = NULL;
|
|
||||||
esxVI_FileInfo *fileInfo = NULL;
|
esxVI_FileInfo *fileInfo = NULL;
|
||||||
char key_candidate[VIR_UUID_STRING_BUFLEN] = "";
|
char key_candidate[VIR_UUID_STRING_BUFLEN] = "";
|
||||||
|
|
||||||
@ -789,6 +788,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
/* Build datastore path and query the UUID */
|
/* Build datastore path and query the UUID */
|
||||||
for (fileInfo = searchResults->file; fileInfo;
|
for (fileInfo = searchResults->file; fileInfo;
|
||||||
fileInfo = fileInfo->_next) {
|
fileInfo = fileInfo->_next) {
|
||||||
|
g_autofree char *volumeName = NULL;
|
||||||
g_autofree char *datastorePath = NULL;
|
g_autofree char *datastorePath = NULL;
|
||||||
g_autofree char *uuid_string = NULL;
|
g_autofree char *uuid_string = NULL;
|
||||||
|
|
||||||
@ -831,8 +831,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
esxVI_String_Free(&propertyNameList);
|
esxVI_String_Free(&propertyNameList);
|
||||||
esxVI_ObjectContent_Free(&datastoreList);
|
esxVI_ObjectContent_Free(&datastoreList);
|
||||||
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
||||||
VIR_FREE(volumeName);
|
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user