Skip to content

Commit

Permalink
Fix "Collectable in a gen2 freelist accessed" when deserializing a me…
Browse files Browse the repository at this point in the history
…thod cache

We deserialize the method cache hash itself. Then we run the work_loop to
deserialize its entries. This may trigger GC. Since the cache at that point is
not referenced by any root, we free it.

Serialization and deserialization runs with allocation in gen2 enabled, so we
don't have tons of MVM_ROOT in the (de-)serialization code. But that only
protects against pointers getting moved, not actually against stuff getting
freed.

Fix by MVMROOTing the cache object itself and also other collectables that we
will still use while running the work_loop.
  • Loading branch information
niner committed Jun 28, 2021
1 parent 6977d05 commit 21f8cad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/6model/serialization.c
Expand Up @@ -3169,8 +3169,10 @@ void MVM_serialization_finish_deserialize_method_cache(MVMThreadContext *tc, MVM

/* Deserialize what we need. */
cache = MVM_serialization_read_ref(tc, sr);
if (sr->working == 1)
work_loop(tc, sr);
MVMROOT3(tc, st, sc, cache, { /* Keep cache from getting freed prematurely */
if (sr->working == 1)
work_loop(tc, sr);
});
MVM_ASSIGN_REF(tc, &(st->header), st->method_cache, cache);

/* Clear up. */
Expand Down

0 comments on commit 21f8cad

Please sign in to comment.