qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] dump.c: Fix memory leak issue in cleanup processing for dump_init()
@ 2014-08-03 15:28 Chen Gang
  2014-08-03 15:56 ` Laszlo Ersek
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Chen Gang @ 2014-08-03 15:28 UTC (permalink / raw)
  To: lcapitulino, lersek, qiaonuohan, pbonzini, agraf, Michael Tokarev
  Cc: qemu-trivial, qemu-devel

In dump_init(), when failure occurs, need notice about 'fd' and memory
mapping. So call dump_cleanup() for it (need let all initializations at
front).

Also simplify dump_cleanup(): remove redundant 'ret' and redundant 'fd'
checking.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 dump.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/dump.c b/dump.c
index ce646bc..71d3e94 100644
--- a/dump.c
+++ b/dump.c
@@ -71,18 +71,14 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)
 
 static int dump_cleanup(DumpState *s)
 {
-    int ret = 0;
-
     guest_phys_blocks_free(&s->guest_phys_blocks);
     memory_mapping_list_free(&s->list);
-    if (s->fd != -1) {
-        close(s->fd);
-    }
+    close(s->fd);
     if (s->resume) {
         vm_start();
     }
 
-    return ret;
+    return 0;
 }
 
 static void dump_error(DumpState *s, const char *reason)
@@ -1499,6 +1495,8 @@ static int dump_init(DumpState *s, int fd, bool has_format,
     s->begin = begin;
     s->length = length;
 
+    memory_mapping_list_init(&s->list);
+
     guest_phys_blocks_init(&s->guest_phys_blocks);
     guest_phys_blocks_append(&s->guest_phys_blocks);
 
@@ -1526,7 +1524,6 @@ static int dump_init(DumpState *s, int fd, bool has_format,
     }
 
     /* get memory mapping */
-    memory_mapping_list_init(&s->list);
     if (paging) {
         qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err);
         if (err != NULL) {
@@ -1622,12 +1619,7 @@ static int dump_init(DumpState *s, int fd, bool has_format,
     return 0;
 
 cleanup:
-    guest_phys_blocks_free(&s->guest_phys_blocks);
-
-    if (s->resume) {
-        vm_start();
-    }
-
+    dump_cleanup(s);
     return -1;
 }
 
-- 
1.7.11.7

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

end of thread, other threads:[~2014-08-14 22:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-03 15:28 [Qemu-devel] [PATCH] dump.c: Fix memory leak issue in cleanup processing for dump_init() Chen Gang
2014-08-03 15:56 ` Laszlo Ersek
2014-08-04 13:51   ` Chen Gang
2014-08-11 19:47     ` Chen Gang
2014-08-04  7:59 ` [Qemu-devel] Cc'ing emails [was: [PATCH] dump.c: Fix memory leak issue in cleanup processing for dump_init()] Michael Tokarev
2014-08-04 14:13   ` Chen Gang
2014-08-04 15:43   ` [Qemu-devel] Cc'ing emails [ Markus Armbruster
2014-08-05  4:41     ` Chen Gang
2014-08-05  7:08       ` Michael Tokarev
2014-08-05  8:07         ` Peter Maydell
2014-08-05 12:20           ` Chen Gang
2014-08-05  9:41         ` Markus Armbruster
2014-08-05 13:25           ` Anthony Liguori
2014-08-12 15:43 ` [Qemu-devel] [PATCH] dump.c: Fix memory leak issue in cleanup processing for dump_init() Laszlo Ersek
2014-08-12 22:19   ` Chen Gang
2014-08-14 20:49 ` Luiz Capitulino
2014-08-14 22:03   ` Chen Gang

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).