From 28664e025d8d0d300065fec310093de9d97b9e83 Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Wed, 31 Jul 2024 14:47:46 +0200 Subject: [PATCH] macos: fix missing pthread mutex init after calloc calls constructor for a mutex in a struct value init-ed with gu_calloc. in path `gcs_core_create() -> gcs_group_init()`, the first one allocates `gcs_core_t* core` with gu_calloc() whereas `gcs_code_t` has `gcs_group_t group` with `gu::Mutex memb_mtx_`. After memory allocation gu::Mutex constructor was not called that lead to an error on Darwin in a call to pthread mutex lock. Signed-off-by: Ivan Prisyazhnyy --- gcs/src/gcs_group.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gcs/src/gcs_group.cpp b/gcs/src/gcs_group.cpp index a46b8ca57..bb355cd98 100644 --- a/gcs/src/gcs_group.cpp +++ b/gcs/src/gcs_group.cpp @@ -61,6 +61,7 @@ gcs_group_init (gcs_group_t* group, gu::Config* const cnf, gcache_t* const cache int const appl_proto_ver) { // here we also create default node instance. + new (&group->memb_mtx_) gu::Mutex(NULL); group->cache = cache; group->act_id_ = GCS_SEQNO_ILL; group->conf_id = GCS_SEQNO_ILL; @@ -185,8 +186,13 @@ gcs_group_free (gcs_group_t* group) if (group->my_address) free ((char*)group->my_address); delete group->vote_history; - gu::Lock lock(group->memb_mtx_); - group_nodes_free (group); + { + gu::Lock lock(group->memb_mtx_); + group_nodes_free (group); + } + + // manually release memb_mtx_ after placement-new. + group->memb_mtx_.~Mutex(); } /* Reset nodes array without breaking the statistics */