mirror of https://github.com/proxmox/mirror_qemu
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>master
parent
c41868152a
commit
84ec9bfaf2
|
@ -46,17 +46,15 @@ struct socket *solookup(struct socket **last, struct socket *head,
|
||||||
struct socket *
|
struct socket *
|
||||||
socreate(Slirp *slirp)
|
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));
|
memset(so, 0, sizeof(struct socket));
|
||||||
so->so_state = SS_NOFDREF;
|
so->so_state = SS_NOFDREF;
|
||||||
so->s = -1;
|
so->s = -1;
|
||||||
so->slirp = slirp;
|
so->slirp = slirp;
|
||||||
so->pollfds_idx = -1;
|
so->pollfds_idx = -1;
|
||||||
}
|
|
||||||
return(so);
|
return so;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -110,7 +108,7 @@ sofree(struct socket *so)
|
||||||
if (so->so_tcpcb) {
|
if (so->so_tcpcb) {
|
||||||
free(so->so_tcpcb);
|
free(so->so_tcpcb);
|
||||||
}
|
}
|
||||||
free(so);
|
g_free(so);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)
|
||||||
|
@ -721,7 +719,7 @@ 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 */
|
/* Don't tcp_attach... we don't need so_snd nor so_rcv */
|
||||||
if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
|
if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
|
||||||
free(so);
|
g_free(so);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
insque(so, &slirp->tcb);
|
insque(so, &slirp->tcb);
|
||||||
|
|
|
@ -432,7 +432,7 @@ findso:
|
||||||
if ((so = socreate(slirp)) == NULL)
|
if ((so = socreate(slirp)) == NULL)
|
||||||
goto dropwithreset;
|
goto dropwithreset;
|
||||||
if (tcp_attach(so) < 0) {
|
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;
|
goto dropwithreset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -475,7 +475,7 @@ void tcp_connect(struct socket *inso)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tcp_attach(so) < 0) {
|
if (tcp_attach(so) < 0) {
|
||||||
free(so); /* NOT sofree */
|
g_free(so); /* NOT sofree */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
so->lhost = inso->lhost;
|
so->lhost = inso->lhost;
|
||||||
|
|
Loading…
Reference in New Issue