[libvirt] [PREPOST 07/17] src/xenxs:Refactor disk config parsing code

Eric Blake eblake at redhat.com
Fri Jul 11 19:44:32 UTC 2014


On 07/11/2014 01:04 PM, Jim Fehlig wrote:
> David Kiarie wrote:
>> From: Kiarie Kahurani <davidkiarie4 at gmail.com>
>>
>> Introduce the function
>>  xenParseXMDisk(..........);
>>
>> Parses disk config
>>
>> signed-off-by: David Kiarie<davidkiarie4 at gmail.com>
>> ---
>>  src/xenxs/xen_xm.c | 204 ++++++++++++++++++++++++++++-------------------------
>>  1 file changed, 108 insertions(+), 96 deletions(-)
>>

>> @@ -912,7 +839,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>>  
>>              /* Maintain list in sorted order according to target device name */
>>              if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
>> -                goto cleanup;
>> +                return -1;
>>  
>>              skipdisk:
>>              list = list->next;
>>   
> 
> The next line here is
> 
>             virDomainDiskDefFree(disk);
> 
> which is not right in the case VIR_APPEND_ELEMENT succeeds (pre-existing
> bug).  'disk' should be set to NULL if VIR_APPEND_ELEMENT succeeds, so
> we don't free the disk we've just added to the disk list.

VIR_APPEND_ELEMENT(, , disk) sets disk=NULL on success, precisely so you
don't have to worry about double-freeing it (if you call the macro, you
are guaranteed either transfer semantics and success, or no change on
failure).


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140711/57045e2d/attachment-0001.sig>


More information about the libvir-list mailing list