[PATCH] virNodeDevPCICapSRIOVVirtualParseXML: fix memleak of addr

Hao Wang posted 1 patch 2 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4a221ca4-0296-926b-4147-e70def3bf3bc@huawei.com
src/conf/node_device_conf.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

[PATCH] virNodeDevPCICapSRIOVVirtualParseXML: fix memleak of addr

Posted by Hao Wang 2 weeks ago
From: Hao Wang <wanghao232@huawei.com>
Subject: [PATCH] virNodeDevPCICapSRIOVVirtualParseXML: fix memleak of addr

virPCIDeviceAddressPtr 'addr' is forgotten to be freed in the branch
'VIR_APPEND_ELEMENT() < 0'. Use g_autoptr instead.

Signed-off-by: Hao Wang <wanghao232@huawei.com>
---
 src/conf/node_device_conf.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index c54015336a..2f63772917 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1489,15 +1489,13 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
         goto cleanup;

     for (i = 0; i < naddresses; i++) {
-        virPCIDeviceAddressPtr addr = NULL;
+        g_autoptr(virPCIDeviceAddress) addr = NULL;

         if (VIR_ALLOC(addr) < 0)
             goto cleanup;

-        if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) {
-            VIR_FREE(addr);
+        if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0)
             goto cleanup;
-        }

         if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
                                pci_dev->num_virtual_functions,
--
2.23.0

Re: [PATCH] virNodeDevPCICapSRIOVVirtualParseXML: fix memleak of addr

Posted by Michal Privoznik 2 weeks ago
On 7/30/20 2:03 PM, Hao Wang wrote:
> From: Hao Wang <wanghao232@huawei.com>
> Subject: [PATCH] virNodeDevPCICapSRIOVVirtualParseXML: fix memleak of addr
> 
> virPCIDeviceAddressPtr 'addr' is forgotten to be freed in the branch
> 'VIR_APPEND_ELEMENT() < 0'. Use g_autoptr instead.
> 
> Signed-off-by: Hao Wang <wanghao232@huawei.com>
> ---
>   src/conf/node_device_conf.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

and pushed. Congratulations on your first libvirt contribution!

Michal