Skip to contentSkip to conversation

drive-mirror:fix memory leak

PATCH Superseded Zhang Min 3 participants 3 messages Jan 22, 2014 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhang Min

author
#0 lore raw

PATCH 1/1 drive-mirror:fix memory leak

In the function mirror_iteration() -> qemu_iovec_init(),
it allocates memory for op->qiov.iov, when the write request calls back, but in the function mirror_iteration_done(), it only frees the op, not free the op->qiov.iov, so this causes memory leak.

---
 block/mirror.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block/mirror.c +1 -0
index 2932bab..9840840 100644
@@ -96,6 +96,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
         bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
     }
 
+    g_free(op->qiov.iov);
     g_slice_free(MirrorOp, op);
     qemu_coroutine_enter(s->common.co, NULL);
 }
Signature · 1 line
1.7.3.1.msysgit.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Zhang Min

In the function mirror_iteration() -> qemu_iovec_init(),
it allocates memory for op->qiov.iov, when the write request calls back, but in the function mirror_iteration_done(), it only frees the op, not free the op->qiov.iov, so this causes memory leak.

---
 block/mirror.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block/mirror.c +1 -0
index 2932bab..9840840 100644
@@ -96,6 +96,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
         bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
     }
 
+    g_free(op->qiov.iov);
     g_slice_free(MirrorOp, op);
     qemu_coroutine_enter(s->common.co, NULL);
 }
Signature · 1 line
1.7.3.1.msysgit.0

In the future please keep maintainers Cc'ed, as noted in the wiki page, so your patch can get better chance of being noticed.

http://wiki.qemu.org/Contribute/SubmitAPatch

Quoted 4 lines

Send patches to the mailing list and CC the relevant maintainer -- look in the MAINTAINERS file to find out who that is. Also try using scripts/getmaintainer.pl from the repository for learning the most common committers for the files you touched.

#2 lore raw
In reply to Zhang Min

Am 22.01.2014 um 08:56 hat Zhang Min geschrieben:

Quoted 15 lines

In the function mirror_iteration() -> qemu_iovec_init(),
it allocates memory for op->qiov.iov, when the write request calls back, but in the function mirror_iteration_done(), it only frees the op, not free the op->qiov.iov, so this causes memory leak.

---
 block/mirror.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
block/mirror.c +0 -0
index 2932bab..9840840 100644

block/mirror.c static void mirror_iteration_done(MirrorOp *op, int ret) · line 102

Quoted 7 lines
block/mirror.c +1 -0
@@ -96,6 +96,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret)
         bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
     }
 
+    g_free(op->qiov.iov);
     g_slice_free(MirrorOp, op);
     qemu_coroutine_enter(s->common.co, NULL);
 }

Please use qemu_iovec_destroy() instead. (I would also move it to right after the for loop that frees the individual buffers in qiov.)

Kevin