[libvirt] [PATCH 04/11] network: Remove conditional settings to resolve resource leak
Osier Yang
jyang at redhat.com
Thu Jan 31 11:02:35 UTC 2013
On 2013年01月31日 03:36, John Ferlan wrote:
> The conditional setting of cmdout in networkBuildDhcpDaemonCommandLine()
> caused Coverity to complain that 'cmd' could be leaked if !cmdout. Since
> the function is local and only called with cmdout being passed those checks
> have been removed.
> ---
> src/network/bridge_driver.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 21255f0..e9a36e5 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -995,7 +995,8 @@ cleanup:
>
> /* build the dnsmasq command line */
> static int
> -networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdout,
> +networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
> + virCommandPtr *cmdout,
> char *pidfile, dnsmasqContext *dctx,
> dnsmasqCapsPtr caps)
> {
> @@ -1027,13 +1028,9 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network, virCommandPtr *cmdou
>
> cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
> virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
> -
> - if (cmdout)
> - *cmdout = cmd;
> + *cmdout = cmd;
> ret = 0;
> cleanup:
> - if (ret< 0)
> - virCommandFree(cmd);
> return ret;
> }
>
Per the function is static, the changes are fine. But to be safe,
using ATTRIBUTE_NONNULL will be better:
static int ATTRIBUTE_NONNULL(2)
networkBuildDhcpDaemonCommandLine (...)
Osier
More information about the libvir-list
mailing list