]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add functions for removing and freeing an item in a dlist
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 29 Mar 2021 10:21:13 +0000 (11:21 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 31 Mar 2021 15:11:44 +0000 (16:11 +0100)
src/lib/util/dlist.h
src/lib/util/pair.c
src/lib/util/pair.h

index 9549aff3cb6e9759230d9b370920a981e606c14b..5d9f8b16cbb2fb3a6d621200674a9d86ca826862 100644 (file)
@@ -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.
index de0c37e101e2237b300aef1ed26eb123941e98f2..b4558404c33a0a91f147fc4304c53d1e4ce0b992 100644 (file)
@@ -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
index ba0678103373b16bf0b3f1f76178cd681dd9044c..b77cab2e2694ffe242e3f1bb4026b6e51096ebfc 100644 (file)
@@ -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);