Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix potential null entry reference #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShaoxunZeng
Copy link

@ShaoxunZeng ShaoxunZeng commented Feb 1, 2021

In function log_append_entry, the code directly copies the raft_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 the raft_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 of append entries) as well as improve the understanding, since we don't assume anything of the raft_entry_t, so that it would be freed by the user after append entries function finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant