diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-04-09 15:12:28 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-04-09 15:12:28 -0700 |
| commit | ee7a77db65f24b3e34a9b9b733887cab3434d225 (patch) | |
| tree | 5fa80a0f9dd66a5537cc85b329903333261a4e43 | |
| parent | 9026f13a25d60a2d39f4233f9213f3d49eb5855a (diff) | |
Check that a never free pointer is on the heap.
This fixes a crash on boards with built-in displays which statically
allocate the display bus. When the pointer is provided to never
free, it tries to allocate on the non-existant heap and crashes.
| -rwxr-xr-x | py/gc.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -945,6 +945,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) { #endif // Alternative gc_realloc impl bool gc_never_free(void *ptr) { + // Check to make sure the pointer is on the heap in the first place. + if (gc_nbytes(ptr) == 0) { + return false; + } // Pointers are stored in a linked list where each block is BYTES_PER_BLOCK long and the first // pointer is the next block of pointers. void ** current_reference_block = MP_STATE_MEM(permanent_pointers); |
