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