Fix bug in linked_list_remove_before

This commit is contained in:
2022-04-19 09:18:03 +08:00
parent 936cba4a8a
commit 930cac261b

View File

@@ -338,13 +338,15 @@ void linked_list_remove(struct LinkedList<T>*& node, void(*free_func)(T) = nullp
} }
if (free_func) free_func(node->d); if (free_func) free_func(node->d);
free(node); free(node);
node = nullptr;
} }
template <typename T> template <typename T>
void linked_list_remove_before(struct LinkedList<T>* node, void(*free_func)(T) = nullptr) { void linked_list_remove_before(struct LinkedList<T>* node, void(*free_func)(T) = nullptr) {
if (!node) return; if (!node) return;
while (node->prev) { while (node->prev) {
linked_list_remove(node->prev, free_func); struct LinkedList<T>* cur = node->prev;
linked_list_remove(cur, free_func);
} }
} }