Skip to content

Commit

Permalink
macos: fix missing pthread mutex init after calloc
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sitano committed Jul 31, 2024
1 parent 300fd48 commit 28664e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gcs/src/gcs_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 28664e0

Please sign in to comment.