Skip to content

Commit 949a0a0

Browse files
[interp] Use existing InterpMethod if allocation and lookup race (#57985)
If two threads both want to get an InterpMethod for the same MonoMethod, and they both see null from the first hash table lookup, make sure that whichever one comes into the jit_mm lock second re-uses the previously inserted InterpMethod, instead of its own version. Without this change, racing threads will overwrite MonoJitInfo:seq_points (in mono_interp_transform_method) which sometimes leads to deallocating the same sequence points multiple times. Fixes #57812 Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
1 parent 1316a45 commit 949a0a0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/mono/mono/mini/interp/interp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,12 @@ mono_interp_get_imethod (MonoMethod *method, MonoError *error)
495495
imethod->param_types [i] = mini_get_underlying_type (sig->params [i]);
496496

497497
jit_mm_lock (jit_mm);
498-
if (!mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method))
498+
InterpMethod *old_imethod;
499+
if (!((old_imethod = mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method))))
499500
mono_internal_hash_table_insert (&jit_mm->interp_code_hash, method, imethod);
501+
else {
502+
imethod = old_imethod; /* leak the newly allocated InterpMethod to the mempool */
503+
}
500504
jit_mm_unlock (jit_mm);
501505

502506
imethod->prof_flags = mono_profiler_get_call_instrumentation_flags (imethod->method);

0 commit comments

Comments
 (0)