qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Ulrich Obergfell <uobergfe@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] vnc: severe memory leak caused by broken palette_destroy() function
Date: Mon, 21 Mar 2011 12:33:48 +0000	[thread overview]
Message-ID: <AANLkTikFqbB7D6Dg5ZfBqhzBWXM8_9Owjyoyu1myBSru@mail.gmail.com> (raw)
In-Reply-To: <732683382.437646.1300708339597.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com>

On Mon, Mar 21, 2011 at 11:52 AM, Ulrich Obergfell <uobergfe@redhat.com> wrote:
>
> The following commit breaks the code of the function palette_destroy().
>
> http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e31e3694afef58ba191cbcc6875ec243e5971268
>
> The broken code causes a severe memory leak of 'VncPalette' structures
> because it never frees anything:
>
>     70 void palette_destroy(VncPalette *palette)
>     71 {
>     72     if (palette == NULL) {
>     73         qemu_free(palette);
>     74     }
>     75 }
>
> Calling qemu_free() unconditionally could be considered. However,
> the original code (prior to the aforementioned commit) returned
> immediately if 'palette' was NULL. In order to be closer to the
> original code, the proposed patch corrects the 'if' statement.
>
> Signed-off-by: Ulrich Obergfell <uobergfe@redhat.com>
>
>
> diff -up ./ui/vnc-palette.c.orig0 ./ui/vnc-palette.c
> --- ./ui/vnc-palette.c.orig0    2011-03-15 03:53:22.000000000 +0100
> +++ ./ui/vnc-palette.c  2011-03-20 11:52:57.257560295 +0100
> @@ -69,7 +69,7 @@ void palette_init(VncPalette *palette, s
>
>  void palette_destroy(VncPalette *palette)
>  {
> -    if (palette == NULL) {
> +    if (palette) {
>         qemu_free(palette);
>     }
>  }

Please drop the if (palette) check entirely because qemu_free(NULL) is
a nop.  There's no need to perform this check at all.

Stefan

      reply	other threads:[~2011-03-21 12:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <649134907.437547.1300708075324.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com>
2011-03-21 11:52 ` [Qemu-devel] vnc: severe memory leak caused by broken palette_destroy() function Ulrich Obergfell
2011-03-21 12:33   ` Stefan Hajnoczi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTikFqbB7D6Dg5ZfBqhzBWXM8_9Owjyoyu1myBSru@mail.gmail.com \
    --to=stefanha@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=uobergfe@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).