[libvirt] [PATCH 5/3] qemu: Resolve Coverity RESOURCE_LEAK
Laine Stump
laine at laine.org
Mon May 25 14:01:38 UTC 2015
On 05/18/2015 09:21 AM, John Ferlan wrote:
> Recent changes to the -M/--machine processing code in qemuParseCommandLine
> caused Coverity to determine there was a possible resource leak with how
> the 'list' is managed. Rather than try to add virStringFreeList calls
> everywhere - just promote list to the top of the variables and free it
> within the error processing code. Also required a couple of other tweaks
> in order to avoid double free's.
ACK.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
> src/qemu/qemu_command.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 3ccd35d..411b7a4 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -12382,6 +12382,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
> size_t i;
> bool nographics = false;
> bool fullscreen = false;
> + char **list = NULL;
> char *path;
> size_t nnics = 0;
> const char **nics = NULL;
> @@ -12849,7 +12850,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
> VIR_FREE(def->name);
> } else if (STREQ(arg, "-M") ||
> STREQ(arg, "-machine")) {
> - char **list;
> char *param;
> size_t j = 0;
>
> @@ -12864,10 +12864,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
> if (STRPREFIX(param, "type="))
> param += strlen("type=");
> if (!strchr(param, '=')) {
> - if (VIR_STRDUP(def->os.machine, param) < 0) {
> - virStringFreeList(list);
> + if (VIR_STRDUP(def->os.machine, param) < 0)
> goto error;
> - }
> j++;
> }
>
> @@ -12912,6 +12910,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
> }
> }
> virStringFreeList(list);
> + list = NULL;
> } else if (STREQ(arg, "-serial")) {
> WANT_VALUE();
> if (STRNEQ(val, "none")) {
> @@ -13385,6 +13384,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
> virDomainDiskDefFree(disk);
> qemuDomainCmdlineDefFree(cmd);
> virDomainDefFree(def);
> + virStringFreeList(list);
> VIR_FREE(nics);
> if (monConfig) {
> virDomainChrSourceDefFree(*monConfig);
More information about the libvir-list
mailing list