From: Peter Krempa Date: Tue, 3 Jun 2014 12:34:23 +0000 (+0200) Subject: network: bridge: Avoid memory leak from networkBuildDhcpDaemonCommandLine X-Git-Tag: v1.2.6-rc1~201 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23c2763b4fe1820375e51d52813845dfe4657056;p=thirdparty%2Flibvirt.git network: bridge: Avoid memory leak from networkBuildDhcpDaemonCommandLine If the leasehelper_path couldn't be found the code would leak the freshly constructed command structure. Re-arrange code to avoid the problem. Found by coverity, broken by baafe668fa56767c031468ccd5df3e62eaa11370. --- diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 51f01fb32c..4fc4c9a66b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1273,15 +1273,14 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, goto cleanup; } - cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); - virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); - /* This helper is used to create custom leases file for libvirt */ if (!(leaseshelper_path = virFileFindResource("libvirt_leaseshelper", "src", LIBEXECDIR))) goto cleanup; + cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps)); + virCommandAddArgFormat(cmd, "--conf-file=%s", configfile); virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path); *cmdout = cmd;