From 356d52e1852c7bec071cb142352ce7b87eaac2f4 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 1 Jun 2020 18:37:10 +0200 Subject: libdiskfs: Add missing node lock around fshelp_rlock_drop_peropen call fshelp_rlock_drop_peropen actually needs the node to be locked for proper waiting atomicity. --- libdiskfs/peropen-rele.c | 7 +++---- libfshelp/fshelp.h | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libdiskfs/peropen-rele.c b/libdiskfs/peropen-rele.c index ee447677..028b5d71 100644 --- a/libdiskfs/peropen-rele.c +++ b/libdiskfs/peropen-rele.c @@ -32,11 +32,10 @@ diskfs_release_peropen (struct peropen *po) if (po->shadow_root_parent) mach_port_deallocate (mach_task_self (), po->shadow_root_parent); + + pthread_mutex_lock (&po->np->lock); fshelp_rlock_drop_peropen (&po->lock_status); - if (fshelp_rlock_peropen_status(&po->lock_status) != LOCK_UN) - diskfs_nput (po->np); - else - diskfs_nrele (po->np); + diskfs_nput (po->np); fshelp_rlock_po_fini (&po->lock_status); free (po->path); diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h index 91bbfe50..94f7f597 100644 --- a/libfshelp/fshelp.h +++ b/libfshelp/fshelp.h @@ -295,7 +295,9 @@ error_t fshelp_rlock_po_init (struct rlock_peropen *po) #endif /* Use extern inlines. */ -/* Release all of the locks held by a given peropen. */ +/* Release all of the locks held by a given peropen. + The mutex held during fshelp_rlock_tweak calls should be also held + whenver this is called. */ error_t fshelp_rlock_drop_peropen (struct rlock_peropen *po); /* Drop the peropen identifier */ -- cgit v1.2.3