Skip to contentSkip to conversation

qemu-sockets: Fix potential memory leak

PATCH Applied Stefan Weil 2 participants 3 messages Sep 1, 2012 – Sep 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-sockets: Fix potential memory leak

The old code leaks variable 'peer'.

---
 qemu-sockets.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Report from smatch:
qemu-sockets.c:404 inet_dgram_opts(101) warn: variable dereferenced before check 'peer' (see line 401)

It looks like this warning does not make sense, but nevertheless it helped me to discover the leak.

Regards,
Stefan Weil

qemu-sockets.c +1 -1
index 361d890..037775b 100644
@@ -353,7 +353,7 @@ int inet_dgram_opts(QemuOpts *opts)
     if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
         fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                 gai_strerror(rc));
-        return -1;
+        goto err;
     }
 
     /* create socket */
Signature · 1 line
1.7.10
#1 lore raw

Am 01.09.2012 09:40, schrieb Stefan Weil:

Quoted 21 lines

The old code leaks variable 'peer'.

---
  qemu-sockets.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Report from smatch:
qemu-sockets.c:404 inet_dgram_opts(101) warn: variable dereferenced before check 'peer' (see line 401)

It looks like this warning does not make sense, but nevertheless it helped me to discover the leak.

Regards,
Stefan Weil

qemu-sockets.c +0 -0
index 361d890..037775b 100644

qemu-sockets.c int inet_dgram_opts(QemuOpts *opts) · line 359

Quoted 8 lines
qemu-sockets.c +1 -1
@@ -353,7 +353,7 @@ int inet_dgram_opts(QemuOpts *opts)
      if (0 != (rc = getaddrinfo(addr, port,&ai,&local))) {
          fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
                  gai_strerror(rc));
-        return -1;
+        goto err;
      }
 
      /* create socket */

Ping? That code is from 2009, so the patch could also be applied to stable (even if the chance of getting that leak is small).

Regards

Stefan Weil

#2 lore raw
In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

The old code leaks variable 'peer'.

---
 qemu-sockets.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines

Report from smatch:
qemu-sockets.c:404 inet_dgram_opts(101) warn: variable dereferenced before check 'peer' (see line 401)

It looks like this warning does not make sense, but nevertheless it helped me to discover the leak.

Regards,
Stefan Weil

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan