[libvirt] [PATCH] virsh: plug memory leak on cmdDomIfGetLink() sucessful path
Eric Blake
eblake at redhat.com
Thu Dec 8 23:47:47 UTC 2011
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111208/5409521e/attachment-0001.sig>
More information about the libvir-list
mailing list