]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "free to tail" function
authorAlan T. DeKok <aland@freeradius.org>
Mon, 4 Apr 2022 19:29:23 +0000 (15:29 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 5 Apr 2022 12:58:52 +0000 (08:58 -0400)
src/lib/util/dlist.h

index c2bf5215f7115db6658ccf2d237eecfbe49215cb..7ae8240a076a2a8295545c54d169e55c659e7c65 100644 (file)
@@ -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); } \