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

Xu Yandong posted 1 patch 4 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1568880091-88040-1-git-send-email-xuyandong2@huawei.com
Test syntax-check passed
src/conf/node_device_conf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt] [PATCH] conf: fix memory leak in virNodeDevPCICapSRIOVVirtualParseXML
Posted by Xu Yandong 4 years, 6 months ago
In function virNodeDevPCICapSRIOVVirtualParseXML, temp variable
addr could leak if VIR_APPEND_ELEMENT fails .

Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/conf/node_device_conf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: fix memory leak in virNodeDevPCICapSRIOVVirtualParseXML
Posted by Daniel Henrique Barboza 4 years, 6 months ago

On 9/19/19 5:01 AM, Xu Yandong wrote:
> In function virNodeDevPCICapSRIOVVirtualParseXML, temp variable
> addr could leak if VIR_APPEND_ELEMENT fails .
>
> Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

>   src/conf/node_device_conf.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> 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;

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: fix memory leak in virNodeDevPCICapSRIOVVirtualParseXML
Posted by Ján Tomko 4 years, 6 months ago
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@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@redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list