Re: [PATCH] Memory Leak Fix: Check def->info->alias before assigning

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

 



On 11/27/2013 08:34 AM, Nehal J Wani wrote:
>> The 'alias' attribute should *not* be parsed from the XML provided by
>> the user. It should only be parsed in the live state XML. In the latter
>> case no codepath should take us to qemuAssignDeviceAliases. So this is
>> certainly not the right fix. It sounds like the test case is flawed to
>> me.
> So, I gave it another round to test the remaining error thrown by
> valgrind. Here is my finding:
> 
> One of the errors received while running valgrind is (not fixed by the
> patch given before):
> 
> ==3915== 9 bytes in 1 blocks are definitely lost in loss record 31 of 129
> ==3915==    at 0x4A0887C: malloc (vg_replace_malloc.c:270)
>     ==3915==    by 0x34268AF275: xmlStrndup (in /usr/lib64/libxml2.so.2.9.1)
>     ==3915==    by 0x4CCD393: virDomainDeviceInfoParseXML.isra.31
> (domain_conf.c:3439)
>     ==3915==    by 0x4CD6A49: virDomainChrDefParseXML (domain_conf.c:7258)
>     ==3915==    by 0x4CEC0C9: virDomainDeviceDefParse (domain_conf.c:9616)
>     ==3915==    by 0x41D14F: testQemuHotplug (qemuhotplugtest.c:247)
>     ==3915==    by 0x41E421: virtTestRun (testutils.c:139)
>     ==3915==    by 0x41C6E3: mymain (qemuhotplugtest.c:428)
>     ==3915==    by 0x41EAB2: virtTestMain (testutils.c:600)
>     ==3915==    by 0x341F421A04: (below main) (libc-start.c:225)
> 
> The corresponding fix is:
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index ec3b958..b7d5390 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5384,7 +5384,7 @@ qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
>              goto cleanup;
>          }
> 
> -        if (VIR_STRDUP(chr->data.file.path, path) < 0)
> +        if (!chr->data.file.path && VIR_STRDUP(chr->data.file.path, path) < 0)

Better might be:

VIR_FREE(chr->data.file.path);
if (VIR_STRDUP(chr->data.file.path, path) < 0)

to just unconditionally set the path to the learned value, no matter
what code path previously populated it.  But I'm not sure that doing the
VIR_FREE in qemu_monitor_json is correct; if it is just the test case
that is passing in a pre-populated chr->data.file.path, then we should
figure out why the test case is doing that, when all other code paths
pass in NULL when expecting the monitor to populate the field.

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