diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2019-12-01 19:20:52 +0000 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2019-12-01 19:20:52 +0000 |
commit | 67a6170caf878258f4beaf85b8585fe1073798b2 (patch) | |
tree | 7621b0231eff64d60cdc934fea57640099db17a4 /src/tcp_subr.c | |
parent | e03380e55d6b8404f5dae64f3ba293b4dbef2dc4 (diff) | |
parent | d78461257158a9f7aff259a57f922b3d20e9fe5e (diff) | |
download | slirp-67a6170caf878258f4beaf85b8585fe1073798b2.zip slirp-67a6170caf878258f4beaf85b8585fe1073798b2.tar.gz slirp-67a6170caf878258f4beaf85b8585fe1073798b2.tar.bz2 |
Merge branch 'mem-cleanups' into 'master'
Mem cleanups
See merge request slirp/libslirp!20
Diffstat (limited to 'src/tcp_subr.c')
-rw-r--r-- | src/tcp_subr.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/tcp_subr.c b/src/tcp_subr.c index 063eff2..3ccea96 100644 --- a/src/tcp_subr.c +++ b/src/tcp_subr.c @@ -255,11 +255,7 @@ struct tcpcb *tcp_newtcpcb(struct socket *so) { register struct tcpcb *tp; - tp = (struct tcpcb *)malloc(sizeof(*tp)); - if (tp == NULL) - return ((struct tcpcb *)0); - - memset((char *)tp, 0, sizeof(struct tcpcb)); + tp = g_new0(struct tcpcb, 1); tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp; /* * 40: length of IPv4 header (20) + TCP header (20) @@ -336,7 +332,7 @@ struct tcpcb *tcp_close(struct tcpcb *tp) remque(tcpiphdr2qlink(tcpiphdr_prev(t))); m_free(m); } - free(tp); + g_free(tp); so->so_tcpcb = NULL; /* clobber input socket cache if we're closing the cached connection */ if (so == slirp->tcp_last_so) @@ -474,10 +470,7 @@ void tcp_connect(struct socket *inso) so = inso; } else { so = socreate(slirp); - if (tcp_attach(so) < 0) { - g_free(so); /* NOT sofree */ - return; - } + tcp_attach(so); so->lhost = inso->lhost; so->so_ffamily = inso->so_ffamily; } @@ -528,14 +521,10 @@ void tcp_connect(struct socket *inso) /* * Attach a TCPCB to a socket. */ -int tcp_attach(struct socket *so) +void tcp_attach(struct socket *so) { - if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) - return -1; - + so->so_tcpcb = tcp_newtcpcb(so); insque(so, &so->slirp->tcb); - - return 0; } /* |