Skip to content

Commit

Permalink
[mono] Fix race during mono_image_storage_open (#55201)
Browse files Browse the repository at this point in the history
  • Loading branch information
uweigand authored Jul 14, 2021
1 parent 01ce681 commit 7bd4724
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mono/mono/metadata/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,11 @@ mono_image_storage_trypublish (MonoImageStorage *candidate, MonoImageStorage **o
gboolean result;
mono_images_storage_lock ();
MonoImageStorage *val = (MonoImageStorage *)g_hash_table_lookup (images_storage_hash, candidate->key);
if (val && !mono_refcount_tryinc (val)) {
// We raced against a mono_image_storage_dtor in progress.
val = NULL;
}
if (val) {
mono_refcount_inc (val);
*out_storage = val;
result = FALSE;
} else {
Expand Down Expand Up @@ -1295,8 +1298,11 @@ mono_image_storage_tryaddref (const char *key, MonoImageStorage **found)
gboolean result = FALSE;
mono_images_storage_lock ();
MonoImageStorage *val = (MonoImageStorage *)g_hash_table_lookup (images_storage_hash, key);
if (val && !mono_refcount_tryinc (val)) {
// We raced against a mono_image_storage_dtor in progress.
val = NULL;
}
if (val) {
mono_refcount_inc (val);
*found = val;
result = TRUE;
}
Expand Down

0 comments on commit 7bd4724

Please sign in to comment.