aboutsummaryrefslogtreecommitdiffstats
path: root/alloc.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-09-18 10:07:02 -0700
committerJunio C Hamano <gitster@pobox.com>2025-09-18 10:07:02 -0700
commit44c0d062bd2fed84ba1ac930a153de37a5280cd3 (patch)
tree478570ca6a65df8185af7a24b5f2dc9a64850a6d /alloc.c
parentMerge branch 'jk/curl-global-trace-components' (diff)
parentalloc: fix dangling pointer in alloc_state cleanup (diff)
downloadgit-44c0d062bd2fed84ba1ac930a153de37a5280cd3.tar.gz
git-44c0d062bd2fed84ba1ac930a153de37a5280cd3.zip
Merge branch 'ne/alloc-free-and-null'
The clear_alloc_state() API function was not fully clearing the structure for reuse, but since nobody reuses it, replace it with a variant that frees the structure as well, making the callers simpler. * ne/alloc-free-and-null: alloc: fix dangling pointer in alloc_state cleanup
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/alloc.c b/alloc.c
index 377e80f5dd..533a045c2a 100644
--- a/alloc.c
+++ b/alloc.c
@@ -36,19 +36,25 @@ struct alloc_state {
int slab_nr, slab_alloc;
};
-struct alloc_state *allocate_alloc_state(void)
+struct alloc_state *alloc_state_alloc(void)
{
return xcalloc(1, sizeof(struct alloc_state));
}
-void clear_alloc_state(struct alloc_state *s)
+void alloc_state_free_and_null(struct alloc_state **s_)
{
+ struct alloc_state *s = *s_;
+
+ if (!s)
+ return;
+
while (s->slab_nr > 0) {
s->slab_nr--;
free(s->slabs[s->slab_nr]);
}
FREE_AND_NULL(s->slabs);
+ FREE_AND_NULL(*s_);
}
static inline void *alloc_node(struct alloc_state *s, size_t node_size)