]> xenbits.xensource.com Git - libvirt.git/commitdiff
nwfilter: Fix memory leak and error path
authorJohn Ferlan <jferlan@redhat.com>
Fri, 29 Sep 2017 13:21:47 +0000 (09:21 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 4 Oct 2017 10:22:02 +0000 (06:22 -0400)
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.

src/nwfilter/nwfilter_gentech_driver.c

index 20bfe3efe5854b3a3e1716caf0a2ee02f2e515fe..840d419bb46a17ae2f4ca05206ce4c963683ba2d 100644 (file)
@@ -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) {