From patchwork Sun Jun 16 11:33:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 251675 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B4D342C016F for ; Sun, 16 Jun 2013 21:33:25 +1000 (EST) Received: from localhost ([::1]:53756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoBD0-00022M-W5 for incoming@patchwork.ozlabs.org; Sun, 16 Jun 2013 07:33:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoBCo-00021D-2o for qemu-devel@nongnu.org; Sun, 16 Jun 2013 07:33:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoBCn-0001y6-4h for qemu-devel@nongnu.org; Sun, 16 Jun 2013 07:33:10 -0400 Received: from qemu.weilnetz.de ([37.221.198.45]:32893 helo=v2201305906712890.yourvserver.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoBCm-0001xv-Va; Sun, 16 Jun 2013 07:33:09 -0400 Received: by v2201305906712890.yourvserver.net (Postfix, from userid 1000) id E07F3182F78; Sun, 16 Jun 2013 13:33:05 +0200 (CEST) From: Stefan Weil To: qemu-trivial Date: Sun, 16 Jun 2013 13:33:05 +0200 Message-Id: <1371382385-20415-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 37.221.198.45 Cc: Stefan Weil , qemu-devel Subject: [Qemu-devel] [PATCH] savevm: Fix potential memory leak 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 The leak was reported by cppcheck. Fix it by moving the g_malloc0 after the argument validity check. Signed-off-by: Stefan Weil --- savevm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/savevm.c b/savevm.c index 2ce439f..b883714 100644 --- a/savevm.c +++ b/savevm.c @@ -479,7 +479,7 @@ static const QEMUFileOps socket_write_ops = { QEMUFile *qemu_fopen_socket(int fd, const char *mode) { - QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); + QEMUFileSocket *s; if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || @@ -488,6 +488,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode) return NULL; } + s = g_malloc0(sizeof(QEMUFileSocket)); s->fd = fd; if (mode[0] == 'w') { qemu_set_block(s->fd);