From: John Ferlan Date: Fri, 29 Sep 2017 13:21:47 +0000 (-0400) Subject: nwfilter: Fix memory leak and error path X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f2fb783bb695153c9e8d22d52a461410c60ca428;p=libvirt.git nwfilter: Fix memory leak and error path 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. --- diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 20bfe3efe5..840d419bb4 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) {