]> git.meshlink.io Git - meshlink/commitdiff
Never call timeout_set() outside callbacks if no callback is set.
authorGuus Sliepen <guus@meshlink.io>
Mon, 15 Feb 2021 21:16:04 +0000 (22:16 +0100)
committerGuus Sliepen <guus@meshlink.io>
Mon, 15 Feb 2021 21:16:04 +0000 (22:16 +0100)
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
src/net.c
src/protocol.c

index c34b24c9643f4bde69e2904877502e78c01f2b86..009839314cba71ca319455d657896c4d8bcd9cd1 100644 (file)
@@ -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
                });
index ce999cba00aebe133d3bb41a36c1d5b1a298ff57..22f8287ff70a232acc2ab8c7f7091308c47f0304 100644 (file)
--- 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
+               });
+       }
 }
 
 /*
index 5da89c7d4ea272549f97603f1dd3261d099045f5..9d1dff971e2b800a803584027aeb914866032be8 100644 (file)
@@ -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)
                        });