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

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 redhat com wrote:
>> From: Alex Jia<ajia 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 redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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