[libvirt] [PATCH 0/2] Handle a couple of new Coverity warnings

Coverity 6.6.1 was recently made available - installed it and a couple more RESOURCE_LEAK's were found in error paths. John Ferlan (2): esx_vi: Resolve Coverity RESOURCE_LEAK in error path esx_driver: Resolve Coverity RESOURCE_LEAK on error paths src/esx/esx_driver.c | 10 +++++----- src/esx/esx_vi.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) -- 1.8.3.1

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 1187bf3..ad1b5dc 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; } -- 1.8.3.1

2013/9/3 John Ferlan <jferlan@redhat.com>:
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(+)
ACK. -- Matthias Bolte http://photron.blogspot.com

New Coverity release found a couple of error paths where memory would be leaked in an error/goto path before being properly handled. --- src/esx/esx_driver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 3ea2dd1..13423d0 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3393,7 +3393,6 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) esxVI_AutoStartPowerInfo *powerInfoList = NULL; esxVI_AutoStartPowerInfo *powerInfo = NULL; esxVI_AutoStartPowerInfo *newPowerInfo = NULL; - bool newPowerInfo_isAppended = false; if (esxVI_EnsureSession(priv->primary) < 0) { return -1; @@ -3468,7 +3467,7 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) goto cleanup; } - newPowerInfo_isAppended = true; + newPowerInfo = NULL; if (esxVI_ReconfigureAutostart (priv->primary, @@ -3491,9 +3490,7 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) esxVI_AutoStartDefaults_Free(&defaults); esxVI_AutoStartPowerInfo_Free(&powerInfoList); - if (!newPowerInfo_isAppended) { - esxVI_AutoStartPowerInfo_Free(&newPowerInfo); - } + esxVI_AutoStartPowerInfo_Free(&newPowerInfo); return result; } @@ -3640,6 +3637,7 @@ esxDomainGetSchedulerParametersFlags(virDomainPtr domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("Shares level has unknown value %d"), (int)sharesInfo->level); + esxVI_SharesInfo_Free(&sharesInfo); goto cleanup; } @@ -3743,6 +3741,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain, } spec->cpuAllocation->shares = sharesInfo; + sharesInfo = NULL; if (params[i].value.i >= 0) { spec->cpuAllocation->shares->level = esxVI_SharesLevel_Custom; @@ -3796,6 +3795,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain, result = 0; cleanup: + esxVI_SharesInfo_Free(&sharesInfo); esxVI_ObjectContent_Free(&virtualMachine); esxVI_VirtualMachineConfigSpec_Free(&spec); esxVI_ManagedObjectReference_Free(&task); -- 1.8.3.1

2013/9/3 John Ferlan <jferlan@redhat.com>:
New Coverity release found a couple of error paths where memory would be leaked in an error/goto path before being properly handled. --- src/esx/esx_driver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

On 09/03/2013 07:55 AM, John Ferlan wrote:
Coverity 6.6.1 was recently made available - installed it and a couple more RESOURCE_LEAK's were found in error paths.
John Ferlan (2): esx_vi: Resolve Coverity RESOURCE_LEAK in error path esx_driver: Resolve Coverity RESOURCE_LEAK on error paths
src/esx/esx_driver.c | 10 +++++----- src/esx/esx_vi.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-)
Pushed... Thanks for the quick review. John
participants (2)
-
John Ferlan
-
Matthias Bolte