From patchwork Mon Aug 18 19:26:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 381105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 556FA140095 for ; Tue, 19 Aug 2014 05:27:30 +1000 (EST) Received: from localhost ([::1]:45327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJSaW-0005Ul-Gn for incoming@patchwork.ozlabs.org; Mon, 18 Aug 2014 15:27:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJSZv-0004ct-4X for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJSZo-0002ic-SW for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:26:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJSZo-0002iU-IV for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:26:44 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7IJQcvt013975 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Aug 2014 15:26:38 -0400 Received: from localhost (ovpn-116-28.ams2.redhat.com [10.36.116.28]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7IJQaWN020692; Mon, 18 Aug 2014 15:26:37 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Mon, 18 Aug 2014 15:26:26 -0400 Message-Id: <1408389987-27831-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1408389987-27831-1-git-send-email-lcapitulino@redhat.com> References: <1408389987-27831-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 2/3] dump.c: Fix memory leak issue in cleanup processing for dump_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Chen Gang 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 Reviewed-by: Laszlo Ersek Signed-off-by: Luiz Capitulino --- 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; }