]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix fr_dlist_pop_tail / fr_dlist_pop_head and remove hack
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 1 Dec 2020 17:34:03 +0000 (10:34 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 1 Dec 2020 17:34:03 +0000 (10:34 -0700)
src/lib/server/tmpl_eval.c
src/lib/util/dlist.h

index c1057f88325e785f37a8236bd2d05fc5f254d86d..b0cfb6706387f16dd2bd1b773255df5f0d1f10e3 100644 (file)
@@ -1291,12 +1291,12 @@ fr_pair_t *tmpl_cursor_init(int *err, TALLOC_CTX *ctx, tmpl_cursor_ctx_t *cc,
  */
 void tmpl_cursor_clear(tmpl_cursor_ctx_t *cc)
 {
-       TALLOC_FREE(cc->pool);                          /* just in case we somehow leaked memory */
-
        if (!fr_dlist_num_elements(&cc->nested)) return;/* Help simplify dealing with unused cursor ctxs */
 
        fr_dlist_remove(&cc->nested, &cc->leaf);        /* Noop if leaf isn't inserted */
        fr_dlist_talloc_free(&cc->nested);
+
+       TALLOC_FREE(cc->pool);
 }
 
 /** Copy pairs matching a #tmpl_t in the current #request_t
index 74897d1e72556ac44e0961d994289d75d50ccfee..8ae78d2c15ca1a2cf2ecf59fadb33b23e3741c24 100644 (file)
@@ -409,7 +409,11 @@ static inline CC_HINT(nonnull(1)) void *fr_dlist_remove(fr_dlist_head_t *list_he
  */
 static inline CC_HINT(nonnull(1)) void *fr_dlist_pop_head(fr_dlist_head_t *list_head)
 {
-       return fr_dlist_remove(list_head, fr_dlist_head(list_head));
+       void *item = fr_dlist_head(list_head);
+
+       (void)fr_dlist_remove(list_head, item);
+
+       return item;    /* fr_dlist_remove returns the previous item */
 }
 
 /** Remove the tail item in a list
@@ -421,7 +425,11 @@ static inline CC_HINT(nonnull(1)) void *fr_dlist_pop_head(fr_dlist_head_t *list_
  */
 static inline CC_HINT(nonnull(1)) void *fr_dlist_pop_tail(fr_dlist_head_t *list_head)
 {
-       return fr_dlist_remove(list_head, fr_dlist_tail(list_head));
+       void *item = fr_dlist_tail(list_head);
+
+       (void)fr_dlist_remove(list_head, item);
+
+       return item;    /* fr_dlist_remove returns the previous item */
 }
 
 /** Check all items in the list are valid