[libvirt] [PATCH 2/2] nwfilter: Fix memory leak and error path

John Ferlan posted 2 patches 8 years, 4 months ago
[libvirt] [PATCH 2/2] nwfilter: Fix memory leak and error path
Posted by John Ferlan 8 years, 4 months ago
Found by Coverity. If virNWFilterHashTablePut, then the 3rd arg @val
must be free'd since it would be leaked.

This also fixes potential problem on the error path where the caller
could assume the virNWFilterHashTablePut was successful when in fact
it failed leading to other issues.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/nwfilter/nwfilter_gentech_driver.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 7a3d115ba..500197bae 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -525,9 +525,12 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                     }
 
                     varAccess = virBufferContentAndReset(&buf);
-                    virNWFilterHashTablePut(missing_vars, varAccess,
-                                            val);
+                    rc = virNWFilterHashTablePut(missing_vars, varAccess, val);
                     VIR_FREE(varAccess);
+                    if (rc < 0) {
+                        virNWFilterVarValueFree(val);
+                        return -1;
+                    }
                 }
             }
         } else if (inc) {
-- 
2.13.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] nwfilter: Fix memory leak and error path
Posted by Erik Skultety 8 years, 4 months ago
On Fri, Sep 29, 2017 at 09:31:09AM -0400, John Ferlan wrote:
> Found by Coverity. If virNWFilterHashTablePut, then the 3rd arg @val
> must be free'd since it would be leaked.
>
> This also fixes potential problem on the error path where the caller
> could assume the virNWFilterHashTablePut was successful when in fact
> it failed leading to other issues.
>
> Signed-off-by: John Ferlan <jferlan@redhat.com>

Reviewed-by: Erik Skultety <eskultet@redhat.com>

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