From: Alan T. DeKok Date: Mon, 4 Apr 2022 19:29:23 +0000 (-0400) Subject: add "free to tail" function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c29212ec421ceea3240a33e2aa0ecf0afb00a29;p=thirdparty%2Ffreeradius-server.git add "free to tail" function --- diff --git a/src/lib/util/dlist.h b/src/lib/util/dlist.h index c2bf5215f7..7ae8240a07 100644 --- a/src/lib/util/dlist.h +++ b/src/lib/util/dlist.h @@ -846,6 +846,26 @@ static inline void *fr_dlist_talloc_free_item(fr_dlist_head_t *list_head, void * return prev; } +/** Free items in a doubly linked list (with talloc) + * + * @param[in] head of list to free. + * @param[in] ptr remove and free from this to the tail. + */ +static inline void fr_dlist_talloc_free_to_tail(fr_dlist_head_t *head, void *ptr) +{ + void *e = ptr, *p; + + if (!ptr) return; /* uninitialized means don't do anything */ + + while (e) { + p = fr_dlist_next(head, e); + (void) fr_dlist_remove(head, e); + talloc_free(e); + e = p; + } +} + + /** Free all items in a doubly linked list (with talloc) * * @param[in] head of list to free. @@ -1169,6 +1189,9 @@ DIAG_OFF(unused-function) \ \ static inline void _name ## _talloc_free(FR_DLIST_HEAD(_name) *list) \ { fr_dlist_talloc_free(&list->head); } \ +\ + static inline void _name ## _talloc_free_to_tail(FR_DLIST_HEAD(_name) *list, _element_type *ptr) \ + { fr_dlist_talloc_free_to_tail(&list->head, ptr); } \ \ static inline void _name ## _talloc_reverse_free(FR_DLIST_HEAD(_name) *list) \ { fr_dlist_talloc_reverse_free(&list->head); } \