From 4a62ea02f44139db41ba6803ec553812a2c0e5f6 Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 16 Nov 2021 09:48:50 +0100 Subject: [PATCH] destroy the r/w lock if there is no shared file --- src/runtime/c/pgf/db.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/c/pgf/db.cxx b/src/runtime/c/pgf/db.cxx index a68ada8fc..c4eb5a113 100644 --- a/src/runtime/c/pgf/db.cxx +++ b/src/runtime/c/pgf/db.cxx @@ -525,6 +525,12 @@ PgfDB::~PgfDB() if (ms != NULL) { unregister_process(); +#ifndef _WIN32 + if (fd < 0) { + pthread_rwlock_destroy(&ms->rwlock); + } +#endif + size_t size = ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t); @@ -690,13 +696,12 @@ void PgfDB::init_state(size_t size) if ((code = pthread_rwlockattr_init(&attr)) != 0) { throw pgf_systemerror(code); } - if (fd > 0) { + if (fd >= 0) { if ((code = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) != 0) { pthread_rwlockattr_destroy(&attr); throw pgf_systemerror(code); } } - memset(&ms->rwlock, 0, sizeof(ms->rwlock)); if ((code = pthread_rwlock_init(&ms->rwlock, &attr)) != 0) { pthread_rwlockattr_destroy(&attr); throw pgf_systemerror(code);