Patchwork net/socket.c : fix memory leak

login
register
mail settings
Submitter Zhi Hui Li
Date Nov. 24, 2011, 8:23 a.m.
Message ID <CAGtkxYxBfYxcVpQopgpkvf-POUf-uDEjjRht5sOye0REyFExAQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/127451/
State New
Headers show

Comments

Zhi Hui Li - Nov. 24, 2011, 8:23 a.m.
Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
---
 net/socket.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Stefan Hajnoczi - Nov. 24, 2011, 10:40 a.m.
On Thu, Nov 24, 2011 at 04:23:00PM +0800, Zhi Hui Li wrote:
> Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
> ---
>  net/socket.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

Thanks, applied to the trivial patches -next tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches-next

Stefan
Markus Armbruster - Nov. 24, 2011, 11:59 a.m.
Since you're fixing net/socket.c: would you be interested in adopting my
untested drive-by fix "[PATCH 0/2] net: socket backend uses
uninitialized variables"?

http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg03888.html

Patch

diff --git a/net/socket.c b/net/socket.c
index e9ef128..0f09164 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -409,6 +409,7 @@  static int net_socket_listen_init(VLANState *vlan,
     fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
     if (fd < 0) {
         perror("socket");
+        g_free(s);
         return -1;
     }
     socket_set_nonblock(fd);
@@ -420,11 +421,13 @@  static int net_socket_listen_init(VLANState *vlan,
     ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
     if (ret < 0) {
         perror("bind");
+        g_free(s);
         return -1;
     }
     ret = listen(fd, 0);
     if (ret < 0) {
         perror("listen");
+        g_free(s);
         return -1;
     }
     s->vlan = vlan;