[libvirt] [PATCH] daemon: Plug memory leak on remoteDispatchAuthList

Alex Jia ajia at redhat.com
Mon Feb 20 16:06:09 UTC 2012

Hello Eric,
As you said, it's impossible to fix this leak by my change, 
and from codes point of view, the failure path hasn't any
memory leak. I suspect valgrind gave a incorrect report, 
and I will check it later.

Thanks for your comment,

----- Original Message -----
From: "Eric Blake" <eblake at redhat.com>
To: "Alex Jia" <ajia at redhat.com>
Cc: libvir-list at redhat.com
Sent: Monday, February 20, 2012 10:24:43 PM
Subject: Re: [libvirt] [PATCH] daemon: Plug memory leak on remoteDispatchAuthList

On 02/20/2012 03:05 AM, Alex Jia wrote:
> Detected by valgrind. Leak is introuduced in commit fcdfa31.
> * daemon/remote.c (remoteDispatchAuthList): fix memory leak on failure path.
> * Actual result

> +++ b/daemon/remote.c
> @@ -2054,6 +2054,7 @@ remoteDispatchAuthList(virNetServerPtr server ATTRIBUTE_UNUSED,
>              if (virAsprintf(&ident, "pid:%lld,uid:%d",
>                              (long long) callerPid, callerUid) < 0) {
>                  virReportOOMError();
> +                VIR_FREE(ident);

How can that possibly be fixing the leak?  If virAsprintf returns < 0,
then ident is guaranteed to be NULL, and you have added a no-op statement.

I wouldn't be surprised if there is still a lurking bug here; after all,
my commit 15a280bb was an attempt to solve a valgrind memory leak, which
was then in turn reworked by Jim in commits c05ec920 and fcdfa31f.  But
we need to diagnose and patch the real problem, if this is the case.

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

More information about the libvir-list mailing list