Skip to content

Conversation

@AlanRuno
Copy link
Owner

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_stake variable was being passed directly to mxd_add_to_rapid_table(). The rapid table takes ownership of node pointers and frees them later (e.g., in mxd_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

  • Verify ownership model: Confirm that 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.
  • Check other call sites: Search for other places that call mxd_add_to_rapid_table() to ensure they all pass heap-allocated pointers. Run: grep -rn "mxd_add_to_rapid_table" src/
  • Run 10-node test: Deploy the fix and run the MXDTestSuite 10-node test to verify nodes no longer crash when receiving the genesis block and all reach Height: 1.

Notes

Crash log that led to this fix:

[2026-01-11T07:17:56Z] INFO [sync]: Stored unsolicited block at height 0
[2026-01-11T07:17:57Z] INFO [rsc]: Rebuilding rapid table from genesis block
free(): invalid pointer

Link to Devin run: https://app.devin.ai/sessions/f0a6357d898e440ea3745d77dfb91d8d
Requested by: Runo (runonetworks@gmail.com) / @AlanRuno

The rapid table takes ownership of node pointers and frees them later
(e.g., in mxd_rebuild_rapid_table_from_blockchain). Previously, a
stack-allocated node_stake was passed directly to mxd_add_to_rapid_table,
causing a 'free(): invalid pointer' crash when the rapid table was rebuilt
after receiving the genesis block.

Now we allocate heap memory for the node before adding it to the rapid table,
and free it if the add fails.
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@AlanRuno AlanRuno merged commit 4bacc4b into main Jan 12, 2026
7 of 9 checks passed
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.

2 participants