diff mbox

qemu-sockets: Fix potential memory leak

Message ID 1346485226-26554-1-git-send-email-sw@weilnetz.de
State Accepted
Headers show

Commit Message

Stefan Weil Sept. 1, 2012, 7:40 a.m. UTC
The old code leaks variable 'peer'.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 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

Comments

Stefan Weil Sept. 20, 2012, 4:55 p.m. UTC | #1
Am 01.09.2012 09:40, schrieb Stefan Weil:
> The old code leaks variable 'peer'.
>
> Signed-off-by: Stefan Weil<sw@weilnetz.de>
> ---
>   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
>
> diff --git a/qemu-sockets.c b/qemu-sockets.c
> index 361d890..037775b 100644
> --- a/qemu-sockets.c
> +++ b/qemu-sockets.c
> @@ -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
Stefan Hajnoczi Sept. 22, 2012, 3:29 p.m. UTC | #2
On Sat, Sep 01, 2012 at 09:40:26AM +0200, Stefan Weil wrote:
> The old code leaks variable 'peer'.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  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

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

Stefan
diff mbox

Patch

diff --git a/qemu-sockets.c b/qemu-sockets.c
index 361d890..037775b 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -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 */