]> git.proxmox.com Git - qemu.git/commitdiff
savevm: Fix potential memory leak
authorStefan Weil <sw@weilnetz.de>
Sun, 16 Jun 2013 11:33:05 +0000 (13:33 +0200)
committerMichael Tokarev <mjt@tls.msk.ru>
Fri, 21 Jun 2013 18:52:50 +0000 (22:52 +0400)
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

index ff5ece651adfd981174561ca46a565c80a9f2d43..48cc2a995f0eed202cc56001f67068180a07d2d2 100644 (file)
--- 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);