diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-12 17:01:01 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-12 17:01:01 +0100 |
| commit | f6f7d6b05b66307aef549086f8dea24f530f49e8 (patch) | |
| tree | cb173ddd58aae3fcf3d4e4cd81344fea2d6e67e7 /handler.c | |
| parent | 87807c690947f4636dc4dd7fddca15f944719f0c (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.
Diffstat (limited to 'handler.c')
| -rw-r--r-- | handler.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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; } |
