[libvirt] [PATCH] qemuMonitorTextAttachDrive: avoid two leaks

Daniel P. Berrange berrange at redhat.com
Mon Jan 25 19:46:26 UTC 2010


On Mon, Jan 25, 2010 at 08:30:19PM +0100, Jim Meyering wrote:
> Coverity reported the first leak: return-(-1)-would-leak-"safe_str".
> I spotted the 2nd.
> 
> >From 6326ab7b52f3550f24015c27407c1d3c2a1fd64d Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering at redhat.com>
> Date: Mon, 25 Jan 2010 20:19:01 +0100
> Subject: [PATCH] qemuMonitorTextAttachDrive: avoid two leaks
> 
> * src/qemu/qemu_monitor_text.c (qemuMonitorTextAttachDrive): Most other
> failures in this function would "goto cleanup", but one mistakenly
> returned directly, skipping the cleanup and resulting in a leak.
> In addition, iterating the "try_command" loop would clobber, and
> thus leak, the "cmd" allocated on the first iteration,
> so be careful to free it in addition to "reply" beforehand.
> ---
>  src/qemu/qemu_monitor_text.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
> index ce5349b..380bcdc 100644
> --- a/src/qemu/qemu_monitor_text.c
> +++ b/src/qemu/qemu_monitor_text.c
> @@ -1881,13 +1881,13 @@ try_command:
>      if (qemudParseDriveAddReply(reply, driveAddr) < 0) {
>          if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
>              VIR_FREE(reply);
> +            VIR_FREE(cmd);
>              tryOldSyntax = 1;
>              goto try_command;
>          }
>          qemudReportError (NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
>                            _("adding %s disk failed: %s"), drivestr, reply);
> -        VIR_FREE(reply);
> -        return -1;
> +        goto cleanup;
>      }
> 
>      ret = 0;

ACK

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list