diff options
-rw-r--r-- | libtrivfs/protid-clean.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libtrivfs/protid-clean.c b/libtrivfs/protid-clean.c index 42879c9e..b986fca0 100644 --- a/libtrivfs/protid-clean.c +++ b/libtrivfs/protid-clean.c @@ -29,11 +29,16 @@ trivfs_clean_protid (void *arg) wasn't initialized to the point of needing user cleanup. */ (*trivfs_protid_destroy_hook) (cred); + /* If we hold the only reference to the peropen, try to get rid of it. */ mutex_lock (&cred->po->cntl->lock); - if (!--cred->po->refcnt) + if (cred->po->refcnt == 1 && trivfs_peropen_destroy_hook) + { + mutex_unlock (&cred->po->cntl->lock); + (*trivfs_peropen_destroy_hook) (cred->po); + mutex_lock (&cred->po->cntl->lock); + } + if (--cred->po->refcnt == 0) { - if (trivfs_peropen_destroy_hook) - (*trivfs_peropen_destroy_hook) (cred->po); ports_port_deref (cred->po->cntl); free (cred->po); } |