From 555717e34528aa1df1bb404751a346d9af3ad75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20R=C5=B1tschl=C3=A9?= Date: Wed, 9 Nov 2022 17:48:14 +0100 Subject: [PATCH] defensive programming in case connections get tidied while there is activity on both file descriptors (fix #355) --- tcp-listener.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tcp-listener.c b/tcp-listener.c index 24dcdea..d3059c7 100644 --- a/tcp-listener.c +++ b/tcp-listener.c @@ -83,6 +83,11 @@ void tcp_read_process(struct loop_info* fd_info, { cnx_collection* collection = fd_info->collection; struct connection* cnx = collection_get_cnx_from_fd(collection, fd); + + /* connection can get tidied if there is an error on the other file + * descriptor -- then cnx is NULL */ + if (!cnx) return; + /* Determine active queue (0 or 1): if fd is that of q[1], active_q = 1, * otherwise it's 0 */ int active_q = active_queue(cnx, fd); @@ -306,6 +311,11 @@ void probing_read_process(struct connection* cnx, void cnx_write_process(struct loop_info* fd_info, int fd) { struct connection* cnx = collection_get_cnx_from_fd(fd_info->collection, fd); + + /* connection can get tidied if there is an error on the other file + * descriptor -- then cnx is NULL */ + if (!cnx) return; + int res; int queue = active_queue(cnx, fd);