py/gc: Fix 2 cases of concurrent access to ATB and FTB.
diff --git a/py/gc.c b/py/gc.c
index b5cf949..a40b987 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -594,13 +594,14 @@
     // get first block
     size_t block = BLOCK_FROM_PTR(ptr);
 
+    GC_ENTER();
+
     // sanity check the ptr is pointing to the head of a block
     if (ATB_GET_KIND(block) != AT_HEAD) {
+        GC_EXIT();
         return NULL;
     }
 
-    GC_ENTER();
-
     if (MP_STATE_MEM(gc_lock_depth) > 0) {
         GC_EXIT();
         return NULL;
@@ -682,6 +683,12 @@
         return ptr_in;
     }
 
+    #if MICROPY_ENABLE_FINALISER
+    bool ftb_state = FTB_GET(block);
+    #else
+    bool ftb_state = false;
+    #endif
+
     GC_EXIT();
 
     if (!allow_move) {
@@ -690,13 +697,7 @@
     }
 
     // can't resize inplace; try to find a new contiguous chain
-    void *ptr_out = gc_alloc(n_bytes,
-#if MICROPY_ENABLE_FINALISER
-        FTB_GET(block)
-#else
-        false
-#endif
-    );
+    void *ptr_out = gc_alloc(n_bytes, ftb_state);
 
     // check that the alloc succeeded
     if (ptr_out == NULL) {