Fix crash: allocate heap memory for nodes added to rapid table #222
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.
Summary
Fixes a "free(): invalid pointer" crash that occurred when rebuilding the rapid table after receiving the genesis block.
The root cause was that a stack-allocated
node_stakevariable was being passed directly tomxd_add_to_rapid_table(). The rapid table takes ownership of node pointers and frees them later (e.g., inmxd_rebuild_rapid_table_from_blockchain). When the rapid table tried to free a stack pointer, it crashed.The fix allocates heap memory for the node before adding it to the rapid table, and frees it if the add operation fails.
Review & Testing Checklist for Human
mxd_add_to_rapid_table()takes ownership of the pointer (stores it directly, doesn't copy). If it copies the data, this change would cause a memory leak.mxd_add_to_rapid_table()to ensure they all pass heap-allocated pointers. Run:grep -rn "mxd_add_to_rapid_table" src/Notes
Crash log that led to this fix:
Link to Devin run: https://app.devin.ai/sessions/f0a6357d898e440ea3745d77dfb91d8d
Requested by: Runo (runonetworks@gmail.com) / @AlanRuno