Skip to content

Commit

Permalink
Merge pull request #2099 from Unity-Technologies/fix-uum-87193
Browse files Browse the repository at this point in the history
Fix issue where collisions in the function pointer to delegate map would result in stale function pointers being used (UUM-87193)
  • Loading branch information
UnityAlex authored Dec 15, 2024
2 parents 578611e + e4542db commit f28663b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,11 @@ delegate_hash_table_add (MonoDelegateHandle d)
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
}
} else {
if (g_hash_table_lookup (delegate_hash_table, delegate_trampoline) == NULL) {
MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
// This delegate will always be associated with its delegate_trampoline in the table.
// We don't free this delegate object because it is too expensive to keep track of these
// pairs and avoid races with the delegate finalization.
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
}
MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
// If a delegate already exists with a matching function pointer we assume it's old as
// we've just jitted a new one and replace it. This is preferred to continuing to run
// with stale data in the map that could be used later.
g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
}
mono_marshal_unlock ();
}
Expand Down

0 comments on commit f28663b

Please sign in to comment.