Proper synchronization for access to destructor hash table

This commit is contained in:
2025-09-07 05:31:33 -07:00
parent d088bc11d6
commit 14fdfbce85

View File

@ -765,11 +765,17 @@ bool refcount_context_add_destructor(const RefcountContext *ctx, void *obj,
}
entry->callback = callback;
entry->user_data = user_data;
if (!ht_insert(ENTRY->destructors, key, entry)) {
if (!lock_entry_mtx(ENTRY)) {
refcount_free(&ctx->alloc, entry);
return false;
}
return true;
bool success = true;
if (!ht_insert(ENTRY->destructors, key, entry)) {
refcount_free(&ctx->alloc, entry);
success = false;
}
unlock_entry_mtx(ENTRY);
return success;
}
/**
@ -782,5 +788,10 @@ bool refcount_context_add_destructor(const RefcountContext *ctx, void *obj,
*/
bool refcount_context_remove_destructor(const RefcountContext *ctx, void *obj,
void *key) {
return ht_remove(ENTRY->destructors, key);
if (!lock_entry_mtx(ENTRY)) {
return false;
}
bool success = ht_remove(ENTRY->destructors, key);
unlock_entry_mtx(ENTRY);
return success;
}