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

Eric Blake eblake at redhat.com
Tue Jun 28 13:10:40 UTC 2011


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 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/20110628/306ade2f/attachment-0001.sig>


More information about the libvir-list mailing list