[libvirt] [PATCH] nwfilter: Don't leak @val

ZhiPeng Lu posted 1 patch 6 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1506502430-4445-1-git-send-email-lu.zhipeng@zte.com.cn
src/conf/nwfilter_ipaddrmap.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[libvirt] [PATCH] nwfilter: Don't leak @val
Posted by ZhiPeng Lu 6 years, 6 months ago
In virNWFilterIPAddrMapAddIPAddr the @val may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
---
 src/conf/nwfilter_ipaddrmap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c
index 446f3de..5242f05 100644
--- a/src/conf/nwfilter_ipaddrmap.c
+++ b/src/conf/nwfilter_ipaddrmap.c
@@ -61,7 +61,10 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
         if (!val)
             goto cleanup;
         ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
-        goto cleanup;
+	 if (ret < 0) {
+	     virNWFilterVarValueFree(val);
+            goto cleanup;
+	 }
     } else {
         if (virNWFilterVarValueAddValue(val, addr) < 0)
             goto cleanup;
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] nwfilter: Don't leak @val
Posted by John Ferlan 6 years, 6 months ago

@subj:

nwfilter: Fix memory leak in virNWFilterIPAddrMapAddIPAddr

On 09/27/2017 04:53 AM, ZhiPeng Lu wrote:
> In virNWFilterIPAddrMapAddIPAddr the @val may be leaked.

Which alters this to be:

If virNWFilterHashTablePut fails, then the @val was leaked.

> 
> Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
> ---
>  src/conf/nwfilter_ipaddrmap.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c
> index 446f3de..5242f05 100644
> --- a/src/conf/nwfilter_ipaddrmap.c
> +++ b/src/conf/nwfilter_ipaddrmap.c
> @@ -61,7 +61,10 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
>          if (!val)
>              goto cleanup;
>          ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
> -        goto cleanup;
> +	 if (ret < 0) {
> +	     virNWFilterVarValueFree(val);
> +            goto cleanup;
> +	 }

Don't use tabs, something that make check syntax-check would have told
you if you had run before posting the patch. Beyond that the comparison
should just be:

        if (ret < 0)
            virNWFilterVarValueFree(val);
        goto cleanup;


I have fixed these for you...

ACK and pushed,

John
>      } else {
>          if (virNWFilterVarValueAddValue(val, addr) < 0)
>              goto cleanup;
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list