Re: [PATCH v2 1/3] libxl: add support for multiple IP addresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 12/11/2017 08:37 AM, Marek Marczykowski-Górecki wrote:
> On Mon, Dec 11, 2017 at 07:58:54AM -0500, John Ferlan wrote:
>>> +char *
>>> +xenMakeIPList(virNetDevIPInfoPtr guestIP)
>>> +{
>>> +    size_t i;
>>> +    char **address_array;
>>> +    char *ret = NULL;
>>> +
>>> +    if (VIR_ALLOC_N(address_array, guestIP->nips + 1) < 0)
>>> +        return NULL;
>>> +
>>> +    for (i = 0; i < guestIP->nips; i++) {
>>> +        address_array[i] = virSocketAddrFormat(&guestIP->ips[i]->address);
>>> +        if (!address_array[i])
>>> +            goto cleanup;
>>> +    }
>>> +    address_array[guestIP->nips] = NULL;
>>> +
>>> +    ret = virStringListJoin((const char**)address_array, " ");
>>> +
>>> + cleanup:
>>> +    while (i > 0)
>>> +        VIR_FREE(address_array[--i]);
>>
>> Coverity notes that address_array is leaked.  May I sugguest
>> "virStringListFree()" on address array?
> 
> Then I should initialize each entry to NULL first (which will be
> overridden a moment later). Is it ok?
> 

Not sure I understand the question as VIR_ALLOC_N allocates
address_array with guestIP->nips + 1 NULL 'char *' entries.  Then your
for loop fills the entries[i].... The "address_array[guestIP->nips] =
NULL;" would seem superfluous too I guess. I wasn't initially looking
beyond the memory leak.   There's plenty of examples using VIR_ALLOC_N
in the code that you can see how each array entry is free'd as well as
the containing structure.

John

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux