]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
v4: Minor fix to map freeing on error (#3996)
authorNick Porter <nick@portercomputing.co.uk>
Thu, 18 Mar 2021 11:40:18 +0000 (11:40 +0000)
committerGitHub <noreply@github.com>
Thu, 18 Mar 2021 11:40:18 +0000 (11:40 +0000)
* Correct fr_dlist_talloc_reverse_free() to clear from the very end

* Free map list in reverse due to talloc parenting

* Don't clear head - it is talloc freed by the caller when an error is returned

src/lib/server/map.c
src/lib/unlang/xlat_tokenize.c
src/lib/util/dlist.h

index 5a299b7cff58f810ff7731360a8006c98b9206df..fae64e983e4dff9f650b197709b7345f05a80be6 100644 (file)
@@ -509,7 +509,11 @@ int map_afrom_cs(TALLOC_CTX *ctx, fr_map_list_t *out, CONF_SECTION *cs,
                if (total++ == max) {
                        cf_log_err(ci, "Map size exceeded");
                error:
-                       fr_dlist_talloc_free(out);
+                       /*
+                        *      Free in reverse as successive entries have their
+                        *      prececessors as talloc parents
+                        */
+                       fr_dlist_talloc_reverse_free(out);
                        return -1;
                }
 
index 409a1bec21886360e85eb525690f001382f57c41..d2e4b2f1e07d0f1759f1df0d62772c67d531adf0 100644 (file)
@@ -519,7 +519,6 @@ static inline int xlat_tokenize_function_args(TALLOC_CTX *ctx, xlat_exp_t **head
                if (func && (func->input_type != XLAT_INPUT_ARGS)) {
                        fr_strerror_const("Function should be called using the syntax %{func:arg}");
                error:
-                       *head = NULL;
                        talloc_free(node);
                        return -1;
                }
index d0de511a2ed0b36dd18860700d7f6e290a02e13b..9549aff3cb6e9759230d9b370920a981e606c14b 100644 (file)
@@ -663,12 +663,13 @@ static inline void fr_dlist_talloc_free(fr_dlist_head_t *head)
  */
 static inline void fr_dlist_talloc_reverse_free(fr_dlist_head_t *head)
 {
-       void *e = NULL;
+       void *e = NULL, *p;
 
        e = fr_dlist_tail(head);
        do {
-               e = fr_dlist_remove(head, e);
+               p = fr_dlist_remove(head, e);
                talloc_free(e);
+               e = p;
        } while (e);
 }