From f508ed408b230c21341778370ab04def8e7aba3a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 15 Nov 2013 15:38:55 +1030 Subject: [PATCH] io: Fix bug where duplex connection is last fd, when another gets deleted. Signed-off-by: Rusty Russell --- ccan/io/poll.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ccan/io/poll.c b/ccan/io/poll.c index 1b11badd..18691e17 100644 --- a/ccan/io/poll.c +++ b/ccan/io/poll.c @@ -105,6 +105,14 @@ static void del_fd(struct fd *fd) fds[n] = fds[num_fds-1]; assert(fds[n]->backend_info == num_fds-1); fds[n]->backend_info = n; + /* If that happens to be a duplex, move that too. */ + if (!fds[n]->listener) { + struct io_conn *c = (void *)fds[n]; + if (c->duplex) { + assert(c->duplex->fd.backend_info == num_fds-1); + c->duplex->fd.backend_info = n; + } + } } else if (num_fds == 1) { /* Free everything when no more fds. */ io_alloc.free(pollfds); @@ -184,6 +192,7 @@ void backend_del_conn(struct io_conn *conn) io_alloc.free(conn->timeout); if (conn->duplex) { /* In case fds[] pointed to the other one. */ + assert(conn->duplex->fd.backend_info == conn->fd.backend_info); fds[conn->fd.backend_info] = &conn->duplex->fd; conn->duplex->duplex = NULL; conn->fd.backend_info = -1; -- 2.39.2