5d360b
From c3bae9746b9d3995369ba2fa315b42b3faf0efe3 Mon Sep 17 00:00:00 2001
5d360b
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
5d360b
Date: Wed, 13 Dec 2017 13:38:48 +0100
5d360b
Subject: [PATCH 17/41] dump.c: Fix memory leak issue in cleanup processing for
5d360b
 dump_init()
5d360b
MIME-Version: 1.0
5d360b
Content-Type: text/plain; charset=UTF-8
5d360b
Content-Transfer-Encoding: 8bit
5d360b
5d360b
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
5d360b
Message-id: <20171213133912.26176-18-marcandre.lureau@redhat.com>
5d360b
Patchwork-id: 78369
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 17/41] dump.c: Fix memory leak issue in cleanup processing for dump_init()
5d360b
Bugzilla: 1411490
5d360b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
5d360b
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
From: Chen Gang <gang.chen.5i5j@gmail.com>
5d360b
5d360b
In dump_init(), when failure occurs, need notice about 'fd' and memory
5d360b
mapping. So call dump_cleanup() for it (need let all initializations at
5d360b
front).
5d360b
5d360b
Also simplify dump_cleanup(): remove redundant 'ret' and redundant 'fd'
5d360b
checking.
5d360b
5d360b
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
5d360b
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
5d360b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
5d360b
5d360b
(cherry picked from commit 2928207ac1bb2751a1554ea0f9a9641179f51488)
5d360b
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 dump.c | 18 +++++-------------
5d360b
 1 file changed, 5 insertions(+), 13 deletions(-)
5d360b
5d360b
diff --git a/dump.c b/dump.c
5d360b
index c902944..c709fc2 100644
5d360b
--- a/dump.c
5d360b
+++ b/dump.c
5d360b
@@ -71,18 +71,14 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)
5d360b
 
5d360b
 static int dump_cleanup(DumpState *s)
5d360b
 {
5d360b
-    int ret = 0;
5d360b
-
5d360b
     guest_phys_blocks_free(&s->guest_phys_blocks);
5d360b
     memory_mapping_list_free(&s->list);
5d360b
-    if (s->fd != -1) {
5d360b
-        close(s->fd);
5d360b
-    }
5d360b
+    close(s->fd);
5d360b
     if (s->resume) {
5d360b
         vm_start();
5d360b
     }
5d360b
 
5d360b
-    return ret;
5d360b
+    return 0;
5d360b
 }
5d360b
 
5d360b
 static void dump_error(DumpState *s, const char *reason)
5d360b
@@ -1505,6 +1501,8 @@ static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
     s->begin = begin;
5d360b
     s->length = length;
5d360b
 
5d360b
+    memory_mapping_list_init(&s->list);
5d360b
+
5d360b
     guest_phys_blocks_init(&s->guest_phys_blocks);
5d360b
     guest_phys_blocks_append(&s->guest_phys_blocks);
5d360b
 
5d360b
@@ -1532,7 +1530,6 @@ static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
     }
5d360b
 
5d360b
     /* get memory mapping */
5d360b
-    memory_mapping_list_init(&s->list);
5d360b
     if (paging) {
5d360b
         qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err;;
5d360b
         if (err != NULL) {
5d360b
@@ -1628,12 +1625,7 @@ static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
     return 0;
5d360b
 
5d360b
 cleanup:
5d360b
-    guest_phys_blocks_free(&s->guest_phys_blocks);
5d360b
-
5d360b
-    if (s->resume) {
5d360b
-        vm_start();
5d360b
-    }
5d360b
-
5d360b
+    dump_cleanup(s);
5d360b
     return -1;
5d360b
 }
5d360b
 
5d360b
-- 
5d360b
1.8.3.1
5d360b