From: Arran Cudbard-Bell Date: Mon, 29 Mar 2021 10:21:13 +0000 (+0100) Subject: Add functions for removing and freeing an item in a dlist X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c1b1d6921d5e64db1884d6cd65ccf2373101e44;p=thirdparty%2Ffreeradius-server.git Add functions for removing and freeing an item in a dlist --- diff --git a/src/lib/util/dlist.h b/src/lib/util/dlist.h index 9549aff3cb6..5d9f8b16cbb 100644 --- a/src/lib/util/dlist.h +++ b/src/lib/util/dlist.h @@ -642,6 +642,22 @@ static inline void fr_dlist_talloc_free_tail(fr_dlist_head_t *list_head) talloc_free(fr_dlist_pop_head(list_head)); } +/** Free the item specified + * + * @param[in] list_head to free item in. + * @param[in] ptr to remove and free. + * @return + * - NULL if no more items in the list. + * - Previous item in the list + */ +static inline void *fr_dlist_talloc_free_item(fr_dlist_head_t *list_head, void *ptr) +{ + void *prev; + prev = fr_dlist_remove(list_head, ptr); + talloc_free(ptr); + return prev; +} + /** Free all items in a doubly linked list (with talloc) * * @param[in] head of list to free. diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index de0c37e101e..b4558404c33 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -410,6 +410,17 @@ void fr_pair_list_free(fr_pair_list_t *list) fr_dlist_talloc_free(&list->head); } +/** Free a given item in a pair list + * + * @param[in] list to remove and free item from. + * @param[in] vp to free. + * @return The vp before the freed item. + */ +fr_pair_t *fr_pair_list_free_item(fr_pair_list_t *list, fr_pair_t *vp) +{ + return fr_dlist_talloc_free_item(&list->head, vp); +} + /** Is a valuepair list empty * * @param[in] list to check diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index ba067810337..b77cab2e269 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -184,6 +184,9 @@ int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp /** @hidecallergraph */ void fr_pair_list_free(fr_pair_list_t *list); +/** @hidecallergraph */ +fr_pair_t *fr_pair_list_free_item(fr_pair_list_t *list, fr_pair_t *vp); + /** @hidecallergraph */ bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull);