From: Stefan Weil Date: Sun, 16 Jun 2013 11:33:05 +0000 (+0200) Subject: savevm: Fix potential memory leak X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4f080057767a684aab60998659e18f98c5fbefc7;p=qemu.git 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 Signed-off-by: Michael Tokarev --- diff --git a/savevm.c b/savevm.c index ff5ece651a..48cc2a995f 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);