Skip to content

Commit ee7a77d

Browse files
committed
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.
1 parent 9026f13 commit ee7a77d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

py/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
945945
#endif // Alternative gc_realloc impl
946946

947947
bool gc_never_free(void *ptr) {
948+
// Check to make sure the pointer is on the heap in the first place.
949+
if (gc_nbytes(ptr) == 0) {
950+
return false;
951+
}
948952
// Pointers are stored in a linked list where each block is BYTES_PER_BLOCK long and the first
949953
// pointer is the next block of pointers.
950954
void ** current_reference_block = MP_STATE_MEM(permanent_pointers);

0 commit comments

Comments
 (0)