From 59e3d6e0995b2db39e4d87436c600e2475a9b502 Mon Sep 17 00:00:00 2001
Message-Id: <59e3d6e0995b2db39e4d87436c600e2475a9b502.1387382496.git.minovotn@redhat.com>
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
From: Nigel Croxon <ncroxon@redhat.com>
Date: Thu, 14 Nov 2013 22:52:38 +0100
Subject: [PATCH 02/46] savevm: Fix potential memory leak
RH-Author: Nigel Croxon <ncroxon@redhat.com>
Message-id: <1384469598-13137-3-git-send-email-ncroxon@redhat.com>
Patchwork-id: 55690
O-Subject: [RHEL7.0 PATCH 02/42] savevm: Fix potential memory leak
Bugzilla: 1011720
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Bugzilla: 1011720
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
>From commit ID:
commit 4f080057767a684aab60998659e18f98c5fbefc7
Author: Stefan Weil <sw@weilnetz.de>
Date: Sun Jun 16 13:33:05 2013 +0200
savevm: Fix potential memory leak
The leak was reported by cppcheck. Fix it by moving the g_malloc0 after
the argument validity check.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
savevm.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
savevm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/savevm.c b/savevm.c
index 4d12d92..4d898af 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);
--
1.7.11.7