aboutsummaryrefslogtreecommitdiff
path: root/teensy
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-11 21:25:44 -0400
committeriamcheeseman <[email protected]>2026-05-11 21:25:44 -0400
commit06cdc35c5a993440a0b61f6e29f6ccbf4ff608ff (patch)
treed66e9a94f0b9e3206058dc3cbf291eb400d342ff /teensy
parent4607ee516f7b2653da59f5c67c39247a4b1b0820 (diff)
detect double frees
Diffstat (limited to 'teensy')
-rw-r--r--teensy/teensy_mem.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/teensy/teensy_mem.c b/teensy/teensy_mem.c
index 735cf55..62088b8 100644
--- a/teensy/teensy_mem.c
+++ b/teensy/teensy_mem.c
@@ -144,19 +144,29 @@ void *ty_realloc(void *ptr, size_t new_size)
void ty_free(void *ptr)
{
- free(ptr);
-
#ifdef TEENSY_DEBUG
+ bool double_free = true;
+
for (int i = 0; i < allocations_len; i++) {
struct alloc *alloc = &allocations[i];
if (alloc->ptr == ptr) {
free(alloc->backtrace);
*alloc = allocations[allocations_len - 1];
allocations_len--;
+ double_free = false;
break;
}
}
+
+ if (double_free) {
+ ty_log_fatal(
+ TY_ERR_MEM,
+ "Double free or freed unowned memory (%p)",
+ ptr
+ );
+ }
#endif // TEENSY_DEBUG
+ free(ptr);
}
int ty_alloc_count(void)