Re: [PATCH] tests: Fix memory leak in virnetmessagetest

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

 



On 06/28/2011 03:16 AM, Osier Yang wrote:
> Detected when playing with "make -C tests valgrind".
> ---
>  tests/virnetmessagetest.c |   35 ++++++++++++++++++++++++-----------
>  1 files changed, 24 insertions(+), 11 deletions(-)
> 

>      if (VIR_ALLOC(err.str3) < 0)
> -        return -1;
> +        goto cleanup;
>      *err.str3 = strdup("Three");

> +cleanup:
> +    VIR_FREE(*err.message);
> +    VIR_FREE(*err.str1);
> +    VIR_FREE(*err.str2);
> +    VIR_FREE(*err.str3);

Ouch - four potential NULL derefs.  You need to write these as:

if (err.str3)
    VIR_FREE(*err.str3);

and so forth.

> +    VIR_FREE(err.message);
> +    VIR_FREE(err.str1);
> +    VIR_FREE(err.str2);
> +    VIR_FREE(err.str3);

But these four are okay.

> +    return ret;

ACK with that fix.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
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]