diff mbox

[v5,4/5] slirp: fix leak

Message ID 20170503223846.6559-5-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau May 3, 2017, 10:38 p.m. UTC
Spotted by ASAN:

/x86_64/hmp/pc-0.12:

Comments

Samuel Thibault May 5, 2017, 11:55 p.m. UTC | #1
Applied to my tree, thanks!
Marc-André Lureau May 26, 2017, 11 a.m. UTC | #2
On Sat, May 6, 2017 at 3:56 AM Samuel Thibault <samuel.thibault@gnu.org>
wrote:

> Applied to my tree, thanks!
>
>
still not in tree, please remove the unnecessary 'if' before merging

thanks!
diff mbox

Patch

=================================================================
==22538==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 224 byte(s) in 1 object(s) allocated from:
    #0 0x7f0f63cdee60 in malloc (/lib64/libasan.so.3+0xc6e60)
    #1 0x556f11ff32d7 in tcp_newtcpcb /home/elmarco/src/qemu/slirp/tcp_subr.c:250
    #2 0x556f11fdb1d1 in tcp_listen /home/elmarco/src/qemu/slirp/socket.c:688
    #3 0x556f11fca9d5 in slirp_add_hostfwd /home/elmarco/src/qemu/slirp/slirp.c:1052
    #4 0x556f11f8db41 in slirp_hostfwd /home/elmarco/src/qemu/net/slirp.c:506
    #5 0x556f11f8dd83 in hmp_hostfwd_add /home/elmarco/src/qemu/net/slirp.c:535

There might be a better way to fix this, but calling slirp tcp_close()
doesn't work.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/socket.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/slirp/socket.c b/slirp/socket.c
index 86927722e1..3b49a69a93 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -100,6 +100,9 @@  sofree(struct socket *so)
   if(so->so_next && so->so_prev)
     remque(so);  /* crashes if so is not in a queue */
 
+  if (so->so_tcpcb) {
+      free(so->so_tcpcb);
+  }
   free(so);
 }