aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-02-12 17:01:01 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-02-12 17:01:01 +0100
commitf6f7d6b05b66307aef549086f8dea24f530f49e8 (patch)
treecb173ddd58aae3fcf3d4e4cd81344fea2d6e67e7
parent87807c690947f4636dc4dd7fddca15f944719f0c (diff)
handler.c: Fix dangling pointer on failed strdup(3)
When the call to realloc(3) returns successfully, h->elem must be updated immediately. Otherwise, a failed call to strdup(3) would cause the caller to free h->elem at shutdown, but h->elem would still contain a dangling pointer, and therefore cause undefined behaviour.
-rw-r--r--handler.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/handler.c b/handler.c
index a7f0303..42489fa 100644
--- a/handler.c
+++ b/handler.c
@@ -335,6 +335,8 @@ int handler_add(struct handler *const h, const char *url,
return -1;
}
+ h->elem = elem;
+
struct elem *const e = &elem[h->n_cfg];
*e = (const struct elem)
@@ -351,7 +353,6 @@ int handler_add(struct handler *const h, const char *url,
return -1;
}
- h->elem = elem;
h->n_cfg = n;
return 0;
}