summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/alloc.c16
-rw-r--r--src/alloc.h10
2 files changed, 25 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 56d8763..8a4dc3a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -163,11 +163,19 @@ void arena_free(struct arena *arena, void *ptr) {
sanitize_free(chunk, arena->size);
}
-void arena_destroy(struct arena *arena) {
+void arena_clear(struct arena *arena) {
for (size_t i = 0; i < arena->nslabs; ++i) {
free(arena->slabs[i]);
}
free(arena->slabs);
+
+ arena->chunks = NULL;
+ arena->nslabs = 0;
+ arena->slabs = NULL;
+}
+
+void arena_destroy(struct arena *arena) {
+ arena_clear(arena);
sanitize_uninit(arena);
}
@@ -280,6 +288,12 @@ void varena_free(struct varena *varena, void *ptr, size_t count) {
arena_free(arena, ptr);
}
+void varena_clear(struct varena *varena) {
+ for (size_t i = 0; i < varena->narenas; ++i) {
+ arena_clear(&varena->arenas[i]);
+ }
+}
+
void varena_destroy(struct varena *varena) {
for (size_t i = 0; i < varena->narenas; ++i) {
arena_destroy(&varena->arenas[i]);
diff --git a/src/alloc.h b/src/alloc.h
index c2ea09b..b5dfa68 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -186,6 +186,11 @@ void *arena_alloc(struct arena *arena);
void arena_free(struct arena *arena, void *ptr);
/**
+ * Free all allocations from an arena.
+ */
+void arena_clear(struct arena *arena);
+
+/**
* Destroy an arena, freeing all allocations.
*/
void arena_destroy(struct arena *arena);
@@ -278,6 +283,11 @@ void *varena_realloc(struct varena *varena, void *ptr, size_t old_count, size_t
void varena_free(struct varena *varena, void *ptr, size_t count);
/**
+ * Free all allocations from a varena.
+ */
+void varena_clear(struct varena *varena);
+
+/**
* Destroy a varena, freeing all allocations.
*/
void varena_destroy(struct varena *varena);