Skip to content

Commit

Permalink
defensive programming in case connections get tidied while there is a…
Browse files Browse the repository at this point in the history
…ctivity on both file descriptors (fix #355)
  • Loading branch information
yrutschle committed Nov 9, 2022
1 parent 02573eb commit 555717e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tcp-listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 555717e

Please sign in to comment.