Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In function
log_append_entry
, the code directly copies theraft_entry_t
into the entries log, which contains the pointer to the data buffer.Since every
append entries
request would create such entries, and not every time these entries would be appended into the log (e.g. they might be appended some time before). I would like to free these entries' memory possession. But free theraft_entry_t
would result in the null reference of the data buffer during the further call of__raft_applylog
function. (since it directly copies the pointer, not the buffer itself)So I think it's better to malloc and copy the data buffer in
log_append_entry
function, which would reduce the memory usage (otherwise there would be memory leak of the redundant call ofappend entries
) as well as improve the understanding, since we don't assume anything of theraft_entry_t
, so that it would be freed by the user afterappend entries
function finished.