Merge pull request #369 from DrChat/handle_release_fix

Fix releasing the primary handle of an object in RemoveHandle
This commit is contained in:
Ben Vanik 2015-07-27 19:59:45 -07:00
commit b1baaa45bc
1 changed files with 11 additions and 24 deletions

View File

@ -165,35 +165,22 @@ X_STATUS ObjectTable::RemoveHandle(X_HANDLE handle) {
return X_STATUS_INVALID_HANDLE;
}
XObject* object = NULL;
{
std::lock_guard<xe::recursive_mutex> lock(table_mutex_);
// Lower 2 bits are ignored.
uint32_t slot = handle >> 2;
// Verify slot.
if (slot > table_capacity_) {
result = X_STATUS_INVALID_HANDLE;
} else {
ObjectTableEntry& entry = table_[slot];
if (entry.object) {
// Release after we lose the lock.
object = entry.object;
} else {
result = X_STATUS_INVALID_HANDLE;
}
entry.object = nullptr;
}
ObjectTableEntry* entry = LookupTable(handle);
if (!entry) {
return X_STATUS_INVALID_HANDLE;
}
if (object) {
// Release the object handle now that it is out of the table.
object->ReleaseHandle();
std::lock_guard<xe::recursive_mutex> lock(table_mutex_);
if (entry->object) {
auto object = entry->object;
entry->object = nullptr;
entry->handle_ref_count = 0;
// Release now that the object has been removed from the table.
object->Release();
}
return result;
return X_STATUS_SUCCESS;
}
ObjectTable::ObjectTableEntry* ObjectTable::LookupTable(X_HANDLE handle) {