[libvirt] [PATCH] 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. --- src/network/bridge_driver.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 51f01fb..4fc4c9a 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; -- 1.9.3

On Tue, Jun 03, 2014 at 02:37:04PM +0200, Peter Krempa wrote:
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. --- src/network/bridge_driver.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 06/03/14 14:38, Daniel P. Berrange wrote:
On Tue, Jun 03, 2014 at 02:37:04PM +0200, Peter Krempa wrote:
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. --- src/network/bridge_driver.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
ACK
Regards, Daniel
Pushed; Thanks. Peter
participants (2)
-
Daniel P. Berrange
-
Peter Krempa