Fix race condition in pfs_dec_of_refcnt (#328)

File operations tested, no regression
This commit is contained in:
Levi Neely 2026-03-03 16:13:22 +01:00 committed by GitHub
parent cb938aa128
commit 3e777665b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -1782,12 +1782,15 @@ void pfs_dec_of_refcnt(psync_openfile_t *of) {
uint32_t refcnt; uint32_t refcnt;
pfs_get_both_locks(of); pfs_get_both_locks(of);
refcnt = --of->refcnt; refcnt = --of->refcnt;
if (!refcnt) if (!refcnt) {
ptree_del(&openfiles, &of->tree); ptree_del(&openfiles, &of->tree);
psql_unlock(); psql_unlock();
pthread_mutex_unlock(&of->mutex); pthread_mutex_unlock(&of->mutex);
if (!refcnt)
pfs_free_openfile(of); pfs_free_openfile(of);
} else {
psql_unlock();
pthread_mutex_unlock(&of->mutex);
}
} }
void pfs_inc_of_refcnt_and_readers(psync_openfile_t *of) { void pfs_inc_of_refcnt_and_readers(psync_openfile_t *of) {