diff options
Diffstat (limited to 'teensy/teensy_mem.c')
| -rw-r--r-- | teensy/teensy_mem.c | 14 |
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) |
