Oh, It's my fault :(, thanks Eric and Osier. Regards, Alex ----- Original Message ----- From: "Eric Blake" <eblake@xxxxxxxxxx> To: "Osier Yang" <jyang@xxxxxxxxxx> Cc: ajia@xxxxxxxxxx, libvir-list@xxxxxxxxxx Sent: Friday, December 9, 2011 7:47:47 AM Subject: Re: [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@xxxxxxxxxx wrote: >> From: Alex Jia<ajia@xxxxxxxxxx> >> >> 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@xxxxxxxxxx +1-919-301-3266 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list