From 79e9a2247a2991b3db47fcea4bcf38e9e006d3ec Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Fri, 28 Jun 2013 15:07:05 -0400 Subject: [PATCH] Resolve valgrind errors for nodedev cap parsing There were two errors, one as a direct result of commit id '8807b285' and the other from cut-n-paste TEST: nodedevxml2xmltest .............. 14 OK ==25735== 3 bytes in 1 blocks are definitely lost in loss record 1 of 24 ==25735== at 0x4A0887C: malloc (vg_replace_malloc.c:270) ==25735== by 0x344D2AF275: xmlStrndup (in /usr/lib64/libxml2.so.2.9.1) ==25735== by 0x4D0C767: virNodeDeviceDefParseNode (node_device_conf.c:997) ==25735== by 0x4D0D3D2: virNodeDeviceDefParse (node_device_conf.c:1337) ==25735== by 0x401CA4: testCompareXMLToXMLHelper (nodedevxml2xmltest.c:28) ==25735== by 0x402B2F: virtTestRun (testutils.c:158) ==25735== by 0x401B27: mymain (nodedevxml2xmltest.c:81) ==25735== by 0x40316A: virtTestMain (testutils.c:722) ==25735== by 0x37C1021A04: (below main) (libc-start.c:225) ==25735== ==25735== 16 bytes in 1 blocks are definitely lost in loss record 10 of 24 ==25735== at 0x4A08A6E: realloc (vg_replace_malloc.c:662) ==25735== by 0x4C7385E: virReallocN (viralloc.c:184) ==25735== by 0x4C73906: virExpandN (viralloc.c:214) ==25735== by 0x4C73B4A: virInsertElementsN (viralloc.c:324) ==25735== by 0x4D0C84C: virNodeDeviceDefParseNode (node_device_conf.c:1026) ==25735== by 0x4D0D3D2: virNodeDeviceDefParse (node_device_conf.c:1337) ==25735== by 0x401CA4: testCompareXMLToXMLHelper (nodedevxml2xmltest.c:28) ==25735== by 0x402B2F: virtTestRun (testutils.c:158) ==25735== by 0x401B27: mymain (nodedevxml2xmltest.c:81) ==25735== by 0x40316A: virtTestMain (testutils.c:722) ==25735== by 0x37C1021A04: (below main) (libc-start.c:225) ==25735== PASS: nodedevxml2xmltest The first error was resolved by adding a missing VIR_FREE(numberStr); in the new function virNodeDevCapPciDevIommuGroupParseXML(). The second error was a bit more opaque as the error was a result of copying the free methodolgy of the existing code in virNodeDevCapsDefFree(). The code would free each of the entries in the array, but not the memory for the array itself. Added the necessary VIR_FREE(data->pci_dev.iommuGroupDevices) and while at it added the missing VIR_FREE(data->pci_dev.virtual_functions) although there wasn't a test that tripped across it (thus it's been lurking since commit id 'a010165d'). --- src/conf/node_device_conf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 96742ef691..087cebb4b1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1034,6 +1034,7 @@ virNodeDevCapPciDevIommuGroupParseXML(xmlXPathContextPtr ctxt, ret = 0; cleanup: ctxt->node = origNode; + VIR_FREE(numberStr); VIR_FREE(addrNodes); VIR_FREE(pciAddr); return ret; @@ -1466,9 +1467,11 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) for (i = 0; i < data->pci_dev.num_virtual_functions; i++) { VIR_FREE(data->pci_dev.virtual_functions[i]); } + VIR_FREE(data->pci_dev.virtual_functions); for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) { VIR_FREE(data->pci_dev.iommuGroupDevices[i]); } + VIR_FREE(data->pci_dev.iommuGroupDevices); break; case VIR_NODE_DEV_CAP_USB_DEV: VIR_FREE(data->usb_dev.product_name); -- 2.47.2