[libvirt] [PATCH] conf: fix memory leak of class_id bitmap

When libvirtd loads active network configs from network state directory, it should release the class_id memory block which was allocated at the time of loading xml from network config directory. virBitmapParse will create a new memory block of bitmap class_id which causes a memory leak. This happens when at least one virtual network is active before. ==12234== 8,216 (24 direct, 8,192 indirect) bytes in 1 blocks are definitely \ lost in loss record 702 of 709 ==12234== at 0x4A06B2F: calloc (vg_replace_malloc.c:593) ==12234== by 0x37AB04D77D: virAlloc (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x37AB04EF89: virBitmapNew (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x37AB0BFB37: virNetworkAssignDef (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x37AB0BFD31: ??? (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x37AB0BFE92: virNetworkLoadAllConfigs (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x10650E5A: ??? (in /usr/lib64/libvirt/connection-driver/libvirt_driver_network.so) ==12234== by 0x37AB0EB72F: virStateInitialize (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x40DE04: ??? (in /usr/sbin/libvirtd) ==12234== by 0x37AB0832E8: ??? (in /usr/lib64/libvirt.so.0.1000.3) ==12234== by 0x3796807D14: start_thread (in /usr/lib64/libpthread-2.16.so) ==12234== by 0x37960F246C: clone (in /usr/lib64/libc-2.16.so) --- src/conf/network_conf.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index c022fe4..7a45414 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1995,14 +1995,16 @@ virNetworkObjUpdateParseFile(const char *filename, ctxt->node = node; class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt); - if (class_id && - virBitmapParse(class_id, 0, + if (class_id) { + virBitmapFree(net->class_id); + if (virBitmapParse(class_id, 0, &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Malformed 'class_id' attribute: %s"), - class_id); - VIR_FREE(class_id); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Malformed 'class_id' attribute: %s"), + class_id); + VIR_FREE(class_id); + goto cleanup; + } } VIR_FREE(class_id); -- 1.7.11.2

On 03/27/2013 09:35 AM, Guannan Ren wrote:
When libvirtd loads active network configs from network state directory, it should release the class_id memory block which was allocated at the time of loading xml from network config directory. virBitmapParse will create a new memory block of bitmap class_id which causes a memory leak.
This happens when at least one virtual network is active before.
class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt); - if (class_id && - virBitmapParse(class_id, 0, + if (class_id) { + virBitmapFree(net->class_id); + if (virBitmapParse(class_id, 0, &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) {
Indentation is off on this line as a result. ACK, and worth pushing for 1.0.4. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/28/2013 01:45 AM, Eric Blake wrote:
On 03/27/2013 09:35 AM, Guannan Ren wrote:
When libvirtd loads active network configs from network state directory, it should release the class_id memory block which was allocated at the time of loading xml from network config directory. virBitmapParse will create a new memory block of bitmap class_id which causes a memory leak.
This happens when at least one virtual network is active before.
class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt); - if (class_id && - virBitmapParse(class_id, 0, + if (class_id) { + virBitmapFree(net->class_id); + if (virBitmapParse(class_id, 0, &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) { Indentation is off on this line as a result.
ACK, and worth pushing for 1.0.4.
Pushed with indentation fixed. Thanks for the review Guannan
participants (2)
-
Eric Blake
-
Guannan Ren