Skip to content

Commit ec7d79d

Browse files
committed
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 <[email protected]>
1 parent 5db72da commit ec7d79d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gcs/src/gcs_group.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ gcs_group_init (gcs_group_t* group, gu::Config* const cnf, gcache_t* const cache
6161
int const appl_proto_ver)
6262
{
6363
// here we also create default node instance.
64+
new (&group->memb_mtx_) gu::Mutex(NULL);
6465
group->cache = cache;
6566
group->act_id_ = GCS_SEQNO_ILL;
6667
group->conf_id = GCS_SEQNO_ILL;
@@ -185,8 +186,13 @@ gcs_group_free (gcs_group_t* group)
185186
if (group->my_address) free ((char*)group->my_address);
186187
delete group->vote_history;
187188

188-
gu::Lock lock(group->memb_mtx_);
189-
group_nodes_free (group);
189+
{
190+
gu::Lock lock(group->memb_mtx_);
191+
group_nodes_free (group);
192+
}
193+
194+
// manually release memb_mtx_ after placement-new.
195+
group->memb_mtx_.~Mutex();
190196
}
191197

192198
/* Reset nodes array without breaking the statistics */

0 commit comments

Comments
 (0)