[libvirt] [PATCH] esx: Fix memory leak when looking up an non-existing domain by name
Matthias Bolte
matthias.bolte at googlemail.com
Sun Aug 15 18:34:47 UTC 2010
2010/8/10 Eric Blake <eblake at redhat.com>:
> On 08/08/2010 02:56 PM, Matthias Bolte wrote:
>> In case an optional object cannot be found the lookup function is
>> left early and the cleanup code is not executed. Add a success label
>> and goto instead of an early return.
>>
>> This pattern occurs in some other functions too.
>> ---
>> src/esx/esx_vi.c | 14 ++++++++------
>> 1 files changed, 8 insertions(+), 6 deletions(-)
>
> Definitely a leak to plug, but:
>
>>
>> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
>> index c6b2b63..b064b11 100644
>> --- a/src/esx/esx_vi.c
>> +++ b/src/esx/esx_vi.c
>> @@ -2254,7 +2254,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
>>
>> if (managedObjectReference == NULL) {
>> if (occurrence == esxVI_Occurrence_OptionalItem) {
>> - return 0;
>> + goto success;
>
> Why not use the idiom:
>
> result = 0;
> goto cleanup;
>
>> } else {
>> ESX_VI_ERROR(VIR_ERR_NO_DOMAIN,
>> _("Could not find domain with UUID '%s'"),
>> @@ -2270,6 +2270,7 @@ esxVI_LookupVirtualMachineByUuid(esxVI_Context *ctx, const unsigned char *uuid,
>> goto cleanup;
>> }
>>
>> + success:
>> result = 0;
>>
>> cleanup:
>
> such that you only have to have one label, instead of adding a new
> label? All three instances follow the same pattern.
>
Here's v2 attached. I also removed two already existing success labels.
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-esx-Fix-memory-leak-when-looking-up-an-non-existing-.diff
Type: text/x-diff
Size: 2798 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100815/b2727f4b/attachment-0001.bin>
More information about the libvir-list
mailing list