Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Willemt Raft
Commits
97d643fa
Unverified
Commit
97d643fa
authored
Nov 17, 2018
by
Willem
Committed by
GitHub
Nov 17, 2018
Browse files
Merge pull request #99 from yossigo/fix/log-clear-memory-leak
Fix a memory leak with log_clear.
parents
27946fac
4aeeb548
Changes
4
Show whitespace changes
Inline
Side-by-side
include/raft.h
View file @
97d643fa
...
...
@@ -407,6 +407,12 @@ typedef struct
* time to free the memory. */
func_logentry_event_f
log_pop
;
/** Callback called for every existing log entry when clearing the log.
* If memory was malloc'd in log_offer and the entry doesn't get a chance
* to go through log_poll or log_pop, this is the last chance to free it.
*/
func_logentry_event_f
log_clear
;
/** Callback for determining which node this configuration log entry
* affects. This call only applies to configuration change log entries.
* @return the node ID of the node */
...
...
include/raft_log.h
View file @
97d643fa
...
...
@@ -15,6 +15,8 @@ void log_free(log_t* me_);
void
log_clear
(
log_t
*
me_
);
void
log_clear_entries
(
log_t
*
me_
);
/**
* Add entry to log.
* Don't add entry if we've already added this entry (based off ID)
...
...
src/raft_log.c
View file @
97d643fa
...
...
@@ -79,6 +79,7 @@ int log_load_from_snapshot(log_t *me_, raft_index_t idx, raft_term_t term)
{
log_private_t
*
me
=
(
log_private_t
*
)
me_
;
log_clear_entries
(
me_
);
log_clear
(
me_
);
me
->
base
=
idx
;
...
...
@@ -122,6 +123,21 @@ void log_clear(log_t* me_)
me
->
base
=
0
;
}
void
log_clear_entries
(
log_t
*
me_
)
{
log_private_t
*
me
=
(
log_private_t
*
)
me_
;
raft_index_t
i
;
if
(
!
me
->
count
||
!
me
->
cb
||
!
me
->
cb
->
log_clear
)
return
;
for
(
i
=
me
->
base
;
i
<=
me
->
base
+
me
->
count
;
i
++
)
{
me
->
cb
->
log_clear
(
me
->
raft
,
raft_get_udata
(
me
->
raft
),
&
me
->
entries
[(
me
->
front
+
i
-
me
->
base
)
%
me
->
size
],
i
);
}
}
/** TODO: rename log_append */
int
log_append_entry
(
log_t
*
me_
,
raft_entry_t
*
ety
)
{
...
...
src/raft_server.c
View file @
97d643fa
...
...
@@ -125,6 +125,7 @@ void raft_clear(raft_server_t* me_)
me
->
last_applied_idx
=
0
;
me
->
num_nodes
=
0
;
me
->
node
=
NULL
;
log_clear_entries
(
me
->
log
);
log_clear
(
me
->
log
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment