[libvirt] [PATCH] node_device: fix memory leak in nodeDeviceSysfsGetSCSIHostCaps

Yi Wang posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1495766388-12658-1-git-send-email-wang.yi59@zte.com.cn
src/node_device/node_device_linux_sysfs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[libvirt] [PATCH] node_device: fix memory leak in nodeDeviceSysfsGetSCSIHostCaps
Posted by Yi Wang 6 years, 10 months ago
The @tmp is allocated in virVHBAGetConfig in virVHBAIsVportCapable
condition, it will lost when virVHBAGetConfig called again.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 src/node_device/node_device_linux_sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index 1b7aa94..a9c7c9c 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -95,7 +95,8 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
             goto cleanup;
         }
 
-         if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
+        VIR_FREE(tmp);
+        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
                                       "npiv_vports_inuse"))) {
             VIR_WARN("Failed to read npiv_vports_inuse for host%d",
                      scsi_host->host);
-- 
1.8.3.1


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device: fix memory leak in nodeDeviceSysfsGetSCSIHostCaps
Posted by Erik Skultety 6 years, 10 months ago
On Thu, May 25, 2017 at 10:39:48PM -0400, Yi Wang wrote:
> The @tmp is allocated in virVHBAGetConfig in virVHBAIsVportCapable
> condition, it will lost when virVHBAGetConfig called again.
>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
>  src/node_device/node_device_linux_sysfs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
> index 1b7aa94..a9c7c9c 100644
> --- a/src/node_device/node_device_linux_sysfs.c
> +++ b/src/node_device/node_device_linux_sysfs.c
> @@ -95,7 +95,8 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
>              goto cleanup;
>          }
>
> -         if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
> +        VIR_FREE(tmp);
> +        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
>                                        "npiv_vports_inuse"))) {
>              VIR_WARN("Failed to read npiv_vports_inuse for host%d",
>                       scsi_host->host);
> --

ACK

I tweaked the commit message a bit, fixed the broken indentation (introduced
prior to your patch - your patch actually made it more visible) and pushed.

Thanks,
Erik

> 1.8.3.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