Re: [PATCHv5 01/19] util: string: Add helper to free non-NULL terminated string arrays

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

 



On 06/20/2014 01:59 AM, Peter Krempa wrote:
> On 06/20/14 00:41, Eric Blake wrote:
>> On 06/19/2014 07:59 AM, Peter Krempa wrote:
>>> Sometimes the length of the string list is known but the array isn't
>>> NULL terminated. Add helper to free the array in such cases.
>>> ---
>>>  src/libvirt_private.syms |  1 +
>>>  src/util/virstring.c     | 20 ++++++++++++++++++++
>>>  src/util/virstring.h     |  1 +
>>>  3 files changed, 22 insertions(+)
>>
>> I'm still not fully convinced we needed this (if you ALWAYS
>> over-allocate the array large enough for a NULL terminator, including in
> 
> Well I'm using it to free a string list that had the individual string
> elements stolen from it, where the regular freeing function would finish
> possibly on the first element as it might be already NULL and stolen.

Ah, _that_ explains it.  Put this reason in your commit message, and
then I'm fine giving ACK.

> 
> Hmm testing a freeing function that frees the entire array? Not sure how
> I'd approach it. Also is it really worth?

Create an array of { "mallocd", NULL, "mallocd", NULL }, then free it.
If the test doesn't crash, and if valgrind doesn't report leaks or
double-free, then it was worth the test.

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

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]