diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2018-11-06 15:13:21 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-11-10 15:07:53 +0100 |
commit | 84ec9bfaf239b61bac3e43f708772937401e0e63 (patch) | |
tree | c51ce911638e94b4a5d91079c0b85491eccf8901 /slirp/socket.c | |
parent | c41868152a95db5f759bb7da491615eca99e9a40 (diff) |
slirp: Use g_new() to allocate sockets in socreate()
The slirp socreate() function can only fail if the attempt
to malloc() the struct socket fails. Switch to using
g_new() instead, which will allow us to remove the
error-handling code from its callers.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'slirp/socket.c')
-rw-r--r-- | slirp/socket.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/slirp/socket.c b/slirp/socket.c index 322383a1f9..35a9a14565 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -46,17 +46,15 @@ struct socket *solookup(struct socket **last, struct socket *head, struct socket * socreate(Slirp *slirp) { - struct socket *so; + struct socket *so = g_new(struct socket, 1); - so = (struct socket *)malloc(sizeof(struct socket)); - if(so) { memset(so, 0, sizeof(struct socket)); so->so_state = SS_NOFDREF; so->s = -1; so->slirp = slirp; so->pollfds_idx = -1; - } - return(so); + + return so; } /* @@ -110,7 +108,7 @@ sofree(struct socket *so) if (so->so_tcpcb) { free(so->so_tcpcb); } - free(so); + g_free(so); } size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np) @@ -721,8 +719,8 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, /* Don't tcp_attach... we don't need so_snd nor so_rcv */ if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) { - free(so); - return NULL; + g_free(so); + return NULL; } insque(so, &slirp->tcb); |