From f6f7d6b05b66307aef549086f8dea24f530f49e8 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 12 Feb 2026 17:01:01 +0100 Subject: 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. --- handler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'handler.c') 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; } -- cgit v1.2.3