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>
This commit is contained in:
parent
90527d2a8b
commit
4f08005776
3
savevm.c
3
savevm.c
|
@ -479,7 +479,7 @@ static const QEMUFileOps socket_write_ops = {
|
||||||
|
|
||||||
QEMUFile *qemu_fopen_socket(int fd, const char *mode)
|
QEMUFile *qemu_fopen_socket(int fd, const char *mode)
|
||||||
{
|
{
|
||||||
QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
|
QEMUFileSocket *s;
|
||||||
|
|
||||||
if (mode == NULL ||
|
if (mode == NULL ||
|
||||||
(mode[0] != 'r' && mode[0] != 'w') ||
|
(mode[0] != 'r' && mode[0] != 'w') ||
|
||||||
|
@ -488,6 +488,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = g_malloc0(sizeof(QEMUFileSocket));
|
||||||
s->fd = fd;
|
s->fd = fd;
|
||||||
if (mode[0] == 'w') {
|
if (mode[0] == 'w') {
|
||||||
qemu_set_block(s->fd);
|
qemu_set_block(s->fd);
|
||||||
|
|
Loading…
Reference in a new issue