From f00c8df9175fc1aed22f3a889ca039beb78bb98d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 15 Feb 2021 22:16:04 +0100 Subject: [PATCH] Never call timeout_set() outside callbacks if no callback is set. We should never try to update a timer if it was never added to the event loop. There were a few places that didn't have an explicit check to prevent this from happening. --- src/meshlink.c | 2 +- src/net.c | 8 +++++--- src/protocol.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index c34b24c9..00983931 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -3863,7 +3863,7 @@ static void channel_retransmit(struct utcp_connection *utcp_connection) { node_t *n = utcp_connection->utcp->priv; meshlink_handle_t *mesh = n->mesh; - if(n->mtuprobes == 31) { + if(n->mtuprobes == 31 && n->mtutimeout.cb) { timeout_set(&mesh->loop, &n->mtutimeout, &(struct timespec) { 0, 0 }); diff --git a/src/net.c b/src/net.c index ce999cba..22f8287f 100644 --- a/src/net.c +++ b/src/net.c @@ -713,9 +713,11 @@ void retry(meshlink_handle_t *mesh) { } /* Kick the ping timeout handler */ - timeout_set(&mesh->loop, &mesh->pingtimer, &(struct timespec) { - 0, 0 - }); + if(mesh->pingtimer.cb) { + timeout_set(&mesh->loop, &mesh->pingtimer, &(struct timespec) { + 0, 0 + }); + } } /* diff --git a/src/protocol.c b/src/protocol.c index 5da89c7d..9d1dff97 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -228,7 +228,7 @@ bool seen_request(meshlink_handle_t *mesh, const char *request) { new->request = xstrdup(request); new->firstseen = mesh->loop.now.tv_sec; - if(!mesh->past_request_tree->head) { + if(!mesh->past_request_tree->head && mesh->past_request_timeout.cb) { timeout_set(&mesh->loop, &mesh->past_request_timeout, &(struct timespec) { 10, prng(mesh, TIMER_FUDGE) }); -- 2.39.5