[libvirt] [PATCH] conf: fix memory leak in virNodeDevPCICapSRIOVVirtualParseXML

Ján Tomko jtomko at redhat.com
Thu Sep 19 13:48:24 UTC 2019


On Thu, Sep 19, 2019 at 04:01:31AM -0400, Xu Yandong wrote:
>In function virNodeDevPCICapSRIOVVirtualParseXML, temp variable
>addr could leak if VIR_APPEND_ELEMENT fails .
>
>Signed-off-by: Xu Yandong <xuyandong2 at huawei.com>
>---
> src/conf/node_device_conf.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>

A nicer fix would be to remove the remaining VIR_FREE(addr) and mark the
declaration with VIR_AUTOFREE

Jano

>diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
>index 618ce8e00e..2d8e03e53e 100644
>--- a/src/conf/node_device_conf.c
>+++ b/src/conf/node_device_conf.c
>@@ -1519,8 +1519,10 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt,
>
>         if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
>                                pci_dev->num_virtual_functions,
>-                               addr) < 0)
>+                               addr) < 0) {
>+            VIR_FREE(addr);
>             goto cleanup;
>+        }
>     }
>
>     pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
>-- 
>2.18.1
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190919/37a889a1/attachment-0001.sig>


More information about the libvir-list mailing list