Skip to content

Commit

Permalink
slirp: fix clearing ifq_so from pending packets
Browse files Browse the repository at this point in the history
The if_fastq and if_batchq contain not only packets, but queues of packets
for the same socket. When sofree frees a socket, it thus has to clear ifq_so
from all the packets from the queues, not only the first.

Signed-off-by: Samuel Thibault <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
sthibaul authored and pm215 committed Aug 30, 2017
1 parent 29c8564 commit 1201d30
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions slirp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,37 @@ socreate(Slirp *slirp)
return(so);
}

/*
* Remove references to so from the given message queue.
*/
static void
soqfree(struct socket *so, struct quehead *qh)
{
struct mbuf *ifq;

for (ifq = (struct mbuf *) qh->qh_link;
(struct quehead *) ifq != qh;
ifq = ifq->ifq_next) {
if (ifq->ifq_so == so) {
struct mbuf *ifm;
ifq->ifq_so = NULL;
for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
ifm->ifq_so = NULL;
}
}
}
}

/*
* remque and free a socket, clobber cache
*/
void
sofree(struct socket *so)
{
Slirp *slirp = so->slirp;
struct mbuf *ifm;

for (ifm = (struct mbuf *) slirp->if_fastq.qh_link;
(struct quehead *) ifm != &slirp->if_fastq;
ifm = ifm->ifq_next) {
if (ifm->ifq_so == so) {
ifm->ifq_so = NULL;
}
}

for (ifm = (struct mbuf *) slirp->if_batchq.qh_link;
(struct quehead *) ifm != &slirp->if_batchq;
ifm = ifm->ifq_next) {
if (ifm->ifq_so == so) {
ifm->ifq_so = NULL;
}
}
soqfree(so, &slirp->if_fastq);
soqfree(so, &slirp->if_batchq);

if (so->so_emu==EMU_RSH && so->extra) {
sofree(so->extra);
Expand Down

0 comments on commit 1201d30

Please sign in to comment.