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

Marek Marczykowski-Górecki marmarek at invisiblethingslab.com
Mon Dec 11 14:35:09 UTC 2017


On Mon, Dec 11, 2017 at 08:55:50AM -0500, John Ferlan wrote:
> 
> 
> 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.

Ah, I've missed the part that VIR_ALLOC_N initialize memory with zeros.

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20171211/2ed23f5a/attachment-0001.sig>


More information about the libvir-list mailing list