Skip to content

Commit

Permalink
Bug#23320254 TEST CASES ARE CONSTANTLY HANGING AND GENERATE MEMORY LE…
Browse files Browse the repository at this point in the history
…AKS (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
  • Loading branch information
tvale committed Aug 16, 2018
1 parent 6e9ded8 commit 006b367
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ process_member_state(Xcom_member_state *ms_info,
return false;
}

m_member_states[p_id]= ms_info;
save_member_state(ms_info, p_id);

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

void Gcs_xcom_state_exchange::save_member_state(
Xcom_member_state *ms_info, const Gcs_member_identifier &p_id) {
/* m_member_states[p_id] may already exist. In that case we delete the
* existing pointer, otherwise it leaks. */
std::map<Gcs_member_identifier, Xcom_member_state *>::iterator
member_state_it = m_member_states.find(p_id);
bool const state_already_exists = (member_state_it != m_member_states.end());
if (state_already_exists) delete member_state_it->second;
m_member_states[p_id] = ms_info;
}


Gcs_xcom_view_identifier *
Gcs_xcom_state_exchange::get_new_view_id()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -506,6 +506,16 @@ class Gcs_xcom_state_exchange: public Gcs_xcom_state_exchange_interface
void fill_member_set(std::vector<Gcs_member_identifier *> &in,
std::set<Gcs_member_identifier *> &pset);

/**
* Stores the member's state and protocol version.
*
* @param ms_info state
* @param p_id member
* @param protocol_version protocol version
*/
void save_member_state(Xcom_member_state *ms_info,
const Gcs_member_identifier &p_id);

Gcs_communication_interface *m_broadcaster;

std::map<Gcs_member_identifier, uint> m_awaited_vector;
Expand Down

0 comments on commit 006b367

Please sign in to comment.