Skip to content

Commit e33806a

Browse files
committed
py/gc: Fix 2 cases of concurrent access to ATB and FTB.
1 parent 7f4658a commit e33806a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

py/gc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,14 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
594594
// get first block
595595
size_t block = BLOCK_FROM_PTR(ptr);
596596

597+
GC_ENTER();
598+
597599
// sanity check the ptr is pointing to the head of a block
598600
if (ATB_GET_KIND(block) != AT_HEAD) {
601+
GC_EXIT();
599602
return NULL;
600603
}
601604

602-
GC_ENTER();
603-
604605
if (MP_STATE_MEM(gc_lock_depth) > 0) {
605606
GC_EXIT();
606607
return NULL;
@@ -682,6 +683,12 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
682683
return ptr_in;
683684
}
684685

686+
#if MICROPY_ENABLE_FINALISER
687+
bool ftb_state = FTB_GET(block);
688+
#else
689+
bool ftb_state = false;
690+
#endif
691+
685692
GC_EXIT();
686693

687694
if (!allow_move) {
@@ -690,13 +697,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
690697
}
691698

692699
// can't resize inplace; try to find a new contiguous chain
693-
void *ptr_out = gc_alloc(n_bytes,
694-
#if MICROPY_ENABLE_FINALISER
695-
FTB_GET(block)
696-
#else
697-
false
698-
#endif
699-
);
700+
void *ptr_out = gc_alloc(n_bytes, ftb_state);
700701

701702
// check that the alloc succeeded
702703
if (ptr_out == NULL) {

0 commit comments

Comments
 (0)