Fix invalid memory reads when GC is on
(cherry picked from commit 46f3955ed886b9987c3605fc88f8ea1795c71b06)