Patchwork [4/4] block: Fix how mirror_run() frees its buffer

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 15, 2013, 1:23 p.m.
Message ID <1358256220-5460-5-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/212160/
State New
Headers show

Comments

Markus Armbruster - Jan. 15, 2013, 1:23 p.m.
It allocates with qemu_blockalign(), therefore it must free with
qemu_vfree(), not g_free().

Since I'm touching it anyway, move the free to a more obviosly correct
place.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Markus Armbruster - Jan. 15, 2013, 2:20 p.m.
Kevin Wolf <kwolf@redhat.com> writes:

> Am 15.01.2013 14:23, schrieb Markus Armbruster:
>> It allocates with qemu_blockalign(), therefore it must free with
>> qemu_vfree(), not g_free().
>> 
>> Since I'm touching it anyway, move the free to a more obviosly correct
>> place.
>
> ...except that it's now leaked for all error cases but the first.

Brain fart caused by looking at the RHEL code, will respin.
Paolo Bonzini - Jan. 15, 2013, 3:20 p.m.
Il 15/01/2013 15:20, Markus Armbruster ha scritto:
>> > Am 15.01.2013 14:23, schrieb Markus Armbruster:
>>> >> It allocates with qemu_blockalign(), therefore it must free with
>>> >> qemu_vfree(), not g_free().
>>> >> 
>>> >> Since I'm touching it anyway, move the free to a more obviosly correct
>>> >> place.
>> >
>> > ...except that it's now leaked for all error cases but the first.
> Brain fart caused by looking at the RHEL code, will respin.
> 
> 

I'll pick this in my own mirror series, if you don't mind.

Paolo

Patch

diff --git a/block/mirror.c b/block/mirror.c
index 8aeacbf..27a7d8c 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -223,9 +223,9 @@  static void coroutine_fn mirror_run(void *opaque)
             break;
         }
     }
+    qemu_vfree(s->buf);
 
 immediate_exit:
-    g_free(s->buf);
     bdrv_set_dirty_tracking(bs, false);
     bdrv_iostatus_disable(s->target);
     if (s->should_complete && ret == 0) {