From 7f953b19094f0684ab305be2ded7c4a2d119b23b Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 3 Sep 2013 07:16:07 -0400 Subject: [PATCH] esx_vi: Resolve Coverity RESOURCE_LEAK in error path New coverity installation determined that the muliple if condition for "*Alloc" and "*AppendToList" could fail during AppendToList thus leaking memory. --- src/esx/esx_vi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 1187bf341b..ad1b5dc50e 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -3524,6 +3524,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, esxVI_FileQuery_DynamicCast(folderFileQuery)) < 0) { goto cleanup; } + folderFileQuery = NULL; } else { if (esxVI_VmDiskFileQuery_Alloc(&vmDiskFileQuery) < 0 || esxVI_VmDiskFileQueryFlags_Alloc(&vmDiskFileQuery->details) < 0 || @@ -3538,6 +3539,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, vmDiskFileQuery->details->hardwareVersion = esxVI_Boolean_False; vmDiskFileQuery->details->controllerType = esxVI_Boolean_True; vmDiskFileQuery->details->diskExtents = esxVI_Boolean_False; + vmDiskFileQuery = NULL; if (esxVI_IsoImageFileQuery_Alloc(&isoImageFileQuery) < 0 || esxVI_FileQuery_AppendToList @@ -3545,6 +3547,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, esxVI_FileQuery_DynamicCast(isoImageFileQuery)) < 0) { goto cleanup; } + isoImageFileQuery = NULL; if (esxVI_FloppyImageFileQuery_Alloc(&floppyImageFileQuery) < 0 || esxVI_FileQuery_AppendToList @@ -3552,6 +3555,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, esxVI_FileQuery_DynamicCast(floppyImageFileQuery)) < 0) { goto cleanup; } + floppyImageFileQuery = NULL; } if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0) { @@ -3621,6 +3625,10 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, VIR_FREE(taskInfoErrorMessage); esxVI_TaskInfo_Free(&taskInfo); esxVI_HostDatastoreBrowserSearchResults_Free(&searchResults); + esxVI_FolderFileQuery_Free(&folderFileQuery); + esxVI_VmDiskFileQuery_Free(&vmDiskFileQuery); + esxVI_IsoImageFileQuery_Free(&isoImageFileQuery); + esxVI_FloppyImageFileQuery_Free(&floppyImageFileQuery); return result; } @@ -3685,6 +3693,7 @@ esxVI_LookupDatastoreContentByDatastoreName vmDiskFileQuery->details->hardwareVersion = esxVI_Boolean_False; vmDiskFileQuery->details->controllerType = esxVI_Boolean_True; vmDiskFileQuery->details->diskExtents = esxVI_Boolean_False; + vmDiskFileQuery = NULL; if (esxVI_IsoImageFileQuery_Alloc(&isoImageFileQuery) < 0 || esxVI_FileQuery_AppendToList @@ -3692,6 +3701,7 @@ esxVI_LookupDatastoreContentByDatastoreName esxVI_FileQuery_DynamicCast(isoImageFileQuery)) < 0) { goto cleanup; } + isoImageFileQuery = NULL; if (esxVI_FloppyImageFileQuery_Alloc(&floppyImageFileQuery) < 0 || esxVI_FileQuery_AppendToList @@ -3699,6 +3709,7 @@ esxVI_LookupDatastoreContentByDatastoreName esxVI_FileQuery_DynamicCast(floppyImageFileQuery)) < 0) { goto cleanup; } + floppyImageFileQuery = NULL; /* Search datastore for files */ if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0) @@ -3737,6 +3748,9 @@ esxVI_LookupDatastoreContentByDatastoreName esxVI_ManagedObjectReference_Free(&task); VIR_FREE(taskInfoErrorMessage); esxVI_TaskInfo_Free(&taskInfo); + esxVI_VmDiskFileQuery_Free(&vmDiskFileQuery); + esxVI_IsoImageFileQuery_Free(&isoImageFileQuery); + esxVI_FloppyImageFileQuery_Free(&floppyImageFileQuery); return result; } -- GitLab