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)
This commit is contained in:
Guannan Ren 2013-03-28 12:10:05 +08:00
parent 02cbd8b67e
commit 7a0f502119

View File

@ -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,
&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;
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;
}
}
VIR_FREE(class_id);