Skip to content

Commit 006b367

Browse files
committed
Bug#23320254 TEST CASES ARE CONSTANTLY HANGING AND GENERATE MEMORY LEAKS (post-fix)
Problem ------- The method Gcs_xcom_state_exchange::process_member_state overwrites an owned pointer without deleting it first, so it leaks. Solution -------- If it exists, delete the existing pointer before overwriting it. Reviewed-by: Andre Negrao <[email protected]> Reviewed-by: Tiago Jorge <[email protected]> RB: 20141
1 parent 6e9ded8 commit 006b367

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_state_exchange.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ process_member_state(Xcom_member_state *ms_info,
618618
return false;
619619
}
620620

621-
m_member_states[p_id]= ms_info;
621+
save_member_state(ms_info, p_id);
622622

623623
/*
624624
The rule of updating the awaited_vector at receiving is simply to
@@ -647,6 +647,17 @@ fill_member_set(std::vector<Gcs_member_identifier *> &in,
647647
std::copy(in.begin(), in.end(), std::inserter(pset, pset.begin()));
648648
}
649649

650+
void Gcs_xcom_state_exchange::save_member_state(
651+
Xcom_member_state *ms_info, const Gcs_member_identifier &p_id) {
652+
/* m_member_states[p_id] may already exist. In that case we delete the
653+
* existing pointer, otherwise it leaks. */
654+
std::map<Gcs_member_identifier, Xcom_member_state *>::iterator
655+
member_state_it = m_member_states.find(p_id);
656+
bool const state_already_exists = (member_state_it != m_member_states.end());
657+
if (state_already_exists) delete member_state_it->second;
658+
m_member_states[p_id] = ms_info;
659+
}
660+
650661

651662
Gcs_xcom_view_identifier *
652663
Gcs_xcom_state_exchange::get_new_view_id()

rapid/plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_state_exchange.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -506,6 +506,16 @@ class Gcs_xcom_state_exchange: public Gcs_xcom_state_exchange_interface
506506
void fill_member_set(std::vector<Gcs_member_identifier *> &in,
507507
std::set<Gcs_member_identifier *> &pset);
508508

509+
/**
510+
* Stores the member's state and protocol version.
511+
*
512+
* @param ms_info state
513+
* @param p_id member
514+
* @param protocol_version protocol version
515+
*/
516+
void save_member_state(Xcom_member_state *ms_info,
517+
const Gcs_member_identifier &p_id);
518+
509519
Gcs_communication_interface *m_broadcaster;
510520

511521
std::map<Gcs_member_identifier, uint> m_awaited_vector;

0 commit comments

Comments
 (0)