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 https://github.com/dotnet/runtime/issues/57812
Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
imethod->param_types [i] = mini_get_underlying_type (sig->params [i]);
jit_mm_lock (jit_mm);
- if (!mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method))
+ InterpMethod *old_imethod;
+ if (!((old_imethod = mono_internal_hash_table_lookup (&jit_mm->interp_code_hash, method))))
mono_internal_hash_table_insert (&jit_mm->interp_code_hash, method, imethod);
+ else {
+ imethod = old_imethod; /* leak the newly allocated InterpMethod to the mempool */
+ }
jit_mm_unlock (jit_mm);
imethod->prof_flags = mono_profiler_get_call_instrumentation_flags (imethod->method);