public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix minor memory leak
@ 2009-04-22 22:15 Nolan
  2009-04-24 20:42 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Nolan @ 2009-04-22 22:15 UTC (permalink / raw)
  To: kvm

Fix a memory leak.  No big deal, since it happens only a bounded # of
times at startup (as far as I can tell) but it makes valgrind complain.

I sent this here since qemu doesn't have the code in question (it
allocates buf on the stack, and thus guess_disk_lchs() usually won't
work with O_DIRECT).

Signed-off-by: Nolan Leake nolan <at> sigbus.net

diff --git a/qemu/block.c b/qemu/block.c
index 7a469ed..3cdebcd 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -771,8 +771,10 @@ static int guess_disk_lchs(BlockDriverState *bs,
     bdrv_get_geometry(bs, &nb_sectors);
 
     ret = bdrv_read(bs, 0, buf, 1);
-    if (ret < 0)
+    if (ret < 0) {
+        qemu_free(buf);
         return -1;
+    }
     /* test msdos magic */
     if (buf[510] != 0x55 || buf[511] != 0xaa) {
         qemu_free(buf);


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix minor memory leak
  2009-04-22 22:15 [PATCH] Fix minor memory leak Nolan
@ 2009-04-24 20:42 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2009-04-24 20:42 UTC (permalink / raw)
  To: Nolan; +Cc: kvm

On Wed, Apr 22, 2009 at 03:15:14PM -0700, Nolan wrote:
> Fix a memory leak.  No big deal, since it happens only a bounded # of
> times at startup (as far as I can tell) but it makes valgrind complain.
> 
> I sent this here since qemu doesn't have the code in question (it
> allocates buf on the stack, and thus guess_disk_lchs() usually won't
> work with O_DIRECT).

Nolan,

block-raw-posix.c raw_pread() handles alignment for O_DIRECT, so it
seems the changes in qemu-kvm are now unnecessary. Can you send
a patch to match upstream QEMU, with the buf on stack? 

TIA

> 
> Signed-off-by: Nolan Leake nolan <at> sigbus.net
> 
> diff --git a/qemu/block.c b/qemu/block.c
> index 7a469ed..3cdebcd 100644
> --- a/qemu/block.c
> +++ b/qemu/block.c
> @@ -771,8 +771,10 @@ static int guess_disk_lchs(BlockDriverState *bs,
>      bdrv_get_geometry(bs, &nb_sectors);
>  
>      ret = bdrv_read(bs, 0, buf, 1);
> -    if (ret < 0)
> +    if (ret < 0) {
> +        qemu_free(buf);
>          return -1;
> +    }
>      /* test msdos magic */
>      if (buf[510] != 0x55 || buf[511] != 0xaa) {
>          qemu_free(buf);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-24 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-22 22:15 [PATCH] Fix minor memory leak Nolan
2009-04-24 20:42 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox