aboutsummaryrefslogtreecommitdiff
path: root/libports/complete-deallocate.c
diff options
context:
space:
mode:
Diffstat (limited to 'libports/complete-deallocate.c')
-rw-r--r--libports/complete-deallocate.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libports/complete-deallocate.c b/libports/complete-deallocate.c
index 4768dab9..0d852f57 100644
--- a/libports/complete-deallocate.c
+++ b/libports/complete-deallocate.c
@@ -29,15 +29,29 @@ _ports_complete_deallocate (struct port_info *pi)
if (pi->port_right)
{
+ struct references result;
+
pthread_rwlock_wrlock (&_ports_htable_lock);
+ refcounts_references (&pi->refcounts, &result);
+ if (result.hard > 0 || result.weak > 0)
+ {
+ /* A reference was reacquired through a hash table lookup.
+ It's fine, we didn't touch anything yet. */
+ pthread_mutex_unlock (&_ports_htable_lock);
+ return;
+ }
+
hurd_ihash_locp_remove (&_ports_htable, pi->ports_htable_entry);
hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry);
pthread_rwlock_unlock (&_ports_htable_lock);
+
mach_port_mod_refs (mach_task_self (), pi->port_right,
MACH_PORT_RIGHT_RECEIVE, -1);
pi->port_right = MACH_PORT_NULL;
}
+ pthread_mutex_lock (&_ports_lock);
+
pi->bucket->count--;
pi->class->count--;