[libvirt] [PATCH 1/4] tests: plug memory leaks
Eric Blake
eblake at redhat.com
Fri Dec 10 21:32:21 UTC 2010
On 12/10/2010 01:07 PM, Laine Stump wrote:
>> +++ b/tests/qemuxml2argvtest.c
>> @@ -86,8 +86,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
>> monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
>> monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
>> monitor_chr.data.nix.listen = 1;
>> - if (!(monitor_chr.info.alias = strdup("monitor")))
>> - goto fail;
>> + monitor_chr.info.alias = (char *)"monitor";
>>
>> flags = QEMUD_CMD_FLAG_VNC_COLON |
>> QEMUD_CMD_FLAG_NO_REBOOT |
>
> Well, to be totally safe and correct with this, you might instead want
> to create a function virDomainChrDefClear(),
test code would be the only client
derived from
> virDomainChrDefFree(), and call that when you're done with monitor_chr
> (or just ALLOC monitor_chr instead of putting it on the stack, then call
> virDomainChrDefFree().
That idea crossed my head, then I noticed it would cause a bogus free()
of data.nix.path unless I turned that into a strdup() as well.
>
> I'm okay with this fix anyway, as it stays within the spirit of the
> original code, and technically does fix the problem, so ACK.
Yep, definitely in the spirit of existing code. Pushed as-is.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101210/d03f2e0f/attachment-0001.sig>
More information about the libvir-list
mailing list