[libvirt] [PATCH] virsh: plug memory leak on cmdDomIfGetLink() sucessful path

Alex Jia ajia at redhat.com
Fri Dec 9 02:21:29 UTC 2011


Oh, It's my fault :(, thanks Eric and Osier.

Regards,
Alex

----- Original Message -----
From: "Eric Blake" <eblake at redhat.com>
To: "Osier Yang" <jyang at redhat.com>
Cc: ajia at redhat.com, libvir-list at redhat.com
Sent: Friday, December 9, 2011 7:47:47 AM
Subject: Re: [libvirt] [PATCH] virsh: plug memory leak on cmdDomIfGetLink() sucessful path

On 12/07/2011 11:22 PM, Osier Yang wrote:
> On 2011年12月08日 14:09, ajia at redhat.com wrote:
>> From: Alex Jia<ajia at redhat.com>
>>
>> Detected by valgrind. Leak introduced in commit dc675f3:
>>
>> * tools/virsh.c: fix memory leak on cmdDomIfGetLink.
>>
> 
> ACK.

Not so fast.  mac is allocated in a loop, so it must be freed in a loop.
 I squashed in before I pushed:

diff --git i/tools/virsh.c w/tools/virsh.c
index 276e1cc..4262d60 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -1538,8 +1538,10 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
                 mac = virXMLPropString(cur, "address");

                 if (STRCASEEQ(mac, iface)){
+                    VIR_FREE(mac);
                     goto hit;
                 }
+                VIR_FREE(mac);
             }
             cur = cur->next;
         }
@@ -1573,7 +1575,6 @@ cleanup:
     if (dom)
         virDomainFree(dom);

-    VIR_FREE(mac);
     return ret;
 }


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





More information about the libvir-list mailing list