Skip to content
Snippets Groups Projects
Commit 3653f514 authored by Damien George's avatar Damien George
Browse files

py/gc: Fix GC+thread bug where ptr gets lost because it's not computed.

GC_EXIT() can cause a pending thread (waiting on the mutex) to be
scheduled right away.  This other thread may trigger a garbage
collection.  If the pointer to the newly-allocated block (allocated by
the original thread) is not computed before the switch (so it's just left
as a block number) then the block will be wrongly reclaimed.

This patch makes sure the pointer is computed before allowing any thread
switch to occur.
parent dbd54e0b
No related branches found
No related tags found
No related merge requests found
......@@ -434,12 +434,13 @@ found:
ATB_FREE_TO_TAIL(bl);
}
GC_EXIT();
// get pointer to first block
// we must create this pointer before unlocking the GC so a collection can find it
void *ret_ptr = (void*)(MP_STATE_MEM(gc_pool_start) + start_block * BYTES_PER_BLOCK);
DEBUG_printf("gc_alloc(%p)\n", ret_ptr);
GC_EXIT();
// zero out the additional bytes of the newly allocated blocks
// This is needed because the blocks may have previously held pointers
// to the heap and will not be set to something else if the caller
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment