return hash_map;
}
-void simple_archiver_hash_map_free(SDArchiverHashMap **hash_map) {
- if (hash_map && *hash_map) {
- for (size_t idx = 0; idx < (*hash_map)->buckets_size; ++idx) {
- SDArchiverLinkedList **linked_list = (*hash_map)->buckets + idx;
+void simple_archiver_hash_map_free_single_ptr(SDArchiverHashMap *hash_map) {
+ if (hash_map) {
+ for (size_t idx = 0; idx < hash_map->buckets_size; ++idx) {
+ SDArchiverLinkedList **linked_list = hash_map->buckets + idx;
simple_archiver_list_free(linked_list);
}
- free((*hash_map)->buckets);
- free(*hash_map);
+ free(hash_map->buckets);
+ free(hash_map);
+ }
+}
+void simple_archiver_hash_map_free(SDArchiverHashMap **hash_map) {
+ if (hash_map && *hash_map) {
+ simple_archiver_hash_map_free_single_ptr(*hash_map);
*hash_map = NULL;
}
}
} SDArchiverHashMap;
SDArchiverHashMap *simple_archiver_hash_map_init(void);
+
+/// It is recommended to use the double-pointer version of hash-map free as
+/// that will ensure the variable holding the pointer will end up pointing to
+/// NULL after free.
+void simple_archiver_hash_map_free_single_ptr(SDArchiverHashMap *hash_map);
void simple_archiver_hash_map_free(SDArchiverHashMap **hash_map);
/// Returns zero on success.
return list;
}
-void simple_archiver_list_free(SDArchiverLinkedList **list) {
- if (list && *list) {
- SDArchiverLLNode *node = (*list)->head;
+void simple_archiver_list_free_single_ptr(SDArchiverLinkedList *list) {
+ if (list) {
+ SDArchiverLLNode *node = list->head;
SDArchiverLLNode *prev;
while (node) {
prev = node;
}
}
- free(*list);
+ free(list);
+ }
+}
+
+void simple_archiver_list_free(SDArchiverLinkedList **list) {
+ if (list && *list) {
+ simple_archiver_list_free_single_ptr(*list);
*list = NULL;
}
}
} SDArchiverLinkedList;
SDArchiverLinkedList *simple_archiver_list_init(void);
+
+/// It is recommended to use the double-pointer version of list free as that
+/// will ensure the variable holding the pointer will end up pointing to NULL
+/// after free.
+void simple_archiver_list_free_single_ptr(SDArchiverLinkedList *list);
void simple_archiver_list_free(SDArchiverLinkedList **list);
/// Returns 0 on success. Puts data at the end of the list
return priority_heap;
}
-void simple_archiver_priority_heap_free(SDArchiverPHeap **priority_heap) {
- if (priority_heap && *priority_heap) {
- for (size_t idx = 1; idx < (*priority_heap)->size + 1; ++idx) {
- if ((*priority_heap)->nodes[idx].is_valid != 0) {
- if ((*priority_heap)->nodes[idx].data_cleanup_fn) {
- (*priority_heap)
- ->nodes[idx]
- .data_cleanup_fn((*priority_heap)->nodes[idx].data);
+void simple_archiver_priority_heap_free_single_ptr(
+ SDArchiverPHeap *priority_heap) {
+ if (priority_heap) {
+ for (size_t idx = 1; idx < priority_heap->size + 1; ++idx) {
+ if (priority_heap->nodes[idx].is_valid != 0) {
+ if (priority_heap->nodes[idx].data_cleanup_fn) {
+ priority_heap->nodes[idx].data_cleanup_fn(
+ priority_heap->nodes[idx].data);
} else {
- free((*priority_heap)->nodes[idx].data);
+ free(priority_heap->nodes[idx].data);
}
- (*priority_heap)->nodes[idx].is_valid = 0;
+ priority_heap->nodes[idx].is_valid = 0;
}
}
- free((*priority_heap)->nodes);
- free(*priority_heap);
+ free(priority_heap->nodes);
+ free(priority_heap);
+ }
+}
+
+void simple_archiver_priority_heap_free(SDArchiverPHeap **priority_heap) {
+ if (priority_heap && *priority_heap) {
+ simple_archiver_priority_heap_free_single_ptr(*priority_heap);
*priority_heap = NULL;
}
}
SDArchiverPHeap *simple_archiver_priority_heap_init(void);
SDArchiverPHeap *simple_archiver_priority_heap_init_less_fn(
int (*less_fn)(long long, long long));
+
+/// It is recommended to use the double-pointer version of priority-heap free
+/// as that will ensure the variable holding the pointer will end up pointing
+/// to NULL after free.
+void simple_archiver_priority_heap_free_single_ptr(
+ SDArchiverPHeap *priority_heap);
void simple_archiver_priority_heap_free(SDArchiverPHeap **priority_heap);
/// If data_cleanup_fn is NULL, then "free()" is used on data when freed.