Commit b3553bf8 authored by Yossi Gottlieb's avatar Yossi Gottlieb
Browse files

Fix memory leak on snapshot loading.

All nodes expect local should be removed when loading a snapshot, and
any prior knowledge about them should be void.
parent 11327cc8
...@@ -1405,8 +1405,10 @@ int raft_begin_load_snapshot( ...@@ -1405,8 +1405,10 @@ int raft_begin_load_snapshot(
{ {
if (raft_get_nodeid(me_) == raft_node_get_id(me->nodes[i])) if (raft_get_nodeid(me_) == raft_node_get_id(me->nodes[i]))
my_node_by_idx = i; my_node_by_idx = i;
else else {
raft_node_set_active(me->nodes[i], 0); raft_node_free(me->nodes[i]);
me->nodes[i] = NULL;
}
} }
/* this will be realloc'd by a raft_add_node */ /* this will be realloc'd by a raft_add_node */
......
...@@ -685,7 +685,10 @@ void TestRaft_leader_sends_appendentries_with_correct_prev_log_idx_when_snapshot ...@@ -685,7 +685,10 @@ void TestRaft_leader_sends_appendentries_with_correct_prev_log_idx_when_snapshot
/* i'm leader */ /* i'm leader */
raft_set_state(r, RAFT_STATE_LEADER); raft_set_state(r, RAFT_STATE_LEADER);
raft_node_t* p = raft_get_node_from_idx(r, 1); /* reload node configuration; we expect the app to decode it from
* the loaded snapshot.
*/
raft_node_t* p = raft_add_node(r, NULL, 2, 0);
CuAssertTrue(tc, NULL != p); CuAssertTrue(tc, NULL != p);
raft_node_set_next_idx(p, 4); raft_node_set_next_idx(p, 4);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment