Skip to content

Commit b52ca73

Browse files
committed
Fix issue where collisions in the function pointer to delegate map would result in stale function pointers being used (UUM-87193)
1 parent f837d93 commit b52ca73

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

mono/metadata/marshal.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,11 @@ delegate_hash_table_add (MonoDelegateHandle d)
407407
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
408408
}
409409
} else {
410-
if (g_hash_table_lookup (delegate_hash_table, delegate_trampoline) == NULL) {
411-
MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
412-
// This delegate will always be associated with its delegate_trampoline in the table.
413-
// We don't free this delegate object because it is too expensive to keep track of these
414-
// pairs and avoid races with the delegate finalization.
415-
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
416-
}
410+
MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
411+
// If a delegate already exists with a matching function pointer we assume it's old as
412+
// we've just jitted a new one and replace it. This is preferred to continuing to run
413+
// with stale data in the map that could be used later.
414+
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
417415
}
418416
mono_marshal_unlock ();
419417
}

0 commit comments

Comments
 (0)