aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-11-06 15:13:21 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-11-10 15:07:53 +0100
commitb104e38f440d42476a498b022b19c96d695373e9 (patch)
tree9301521ce390d63717afda18ec654c2833257b66
parenta095b4649f6eb1f5b7b9c1a9a26adc13601f3377 (diff)
downloadslirp-b104e38f440d42476a498b022b19c96d695373e9.zip
slirp-b104e38f440d42476a498b022b19c96d695373e9.tar.gz
slirp-b104e38f440d42476a498b022b19c96d695373e9.tar.bz2
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>
-rw-r--r--socket.c22
-rw-r--r--tcp_input.c2
-rw-r--r--tcp_subr.c2
3 files changed, 12 insertions, 14 deletions
diff --git a/socket.c b/socket.c
index b0b4701..598d815 100644
--- a/socket.c
+++ b/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);
+ memset(so, 0, sizeof(struct socket));
+ so->so_state = SS_NOFDREF;
+ so->s = -1;
+ so->slirp = slirp;
+ so->pollfds_idx = -1;
+
+ return so;
}
/*
@@ -107,7 +105,7 @@ void 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,7 +719,7 @@ struct socket *tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport,
/* Don't tcp_attach... we don't need so_snd nor so_rcv */
if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
- free(so);
+ g_free(so);
return NULL;
}
insque(so, &slirp->tcb);
diff --git a/tcp_input.c b/tcp_input.c
index eb4a326..f4d4b52 100644
--- a/tcp_input.c
+++ b/tcp_input.c
@@ -433,7 +433,7 @@ findso:
if ((so = socreate(slirp)) == NULL)
goto dropwithreset;
if (tcp_attach(so) < 0) {
- free(so); /* Not sofree (if it failed, it's not insqued) */
+ g_free(so); /* Not sofree (if it failed, it's not insqued) */
goto dropwithreset;
}
diff --git a/tcp_subr.c b/tcp_subr.c
index 02e7f7c..bad14fd 100644
--- a/tcp_subr.c
+++ b/tcp_subr.c
@@ -473,7 +473,7 @@ void tcp_connect(struct socket *inso)
return;
}
if (tcp_attach(so) < 0) {
- free(so); /* NOT sofree */
+ g_free(so); /* NOT sofree */
return;
}
so->lhost = inso->lhost;