fix(memory_pool): add thread safety, overflow checks, and double-free protection#85
Closed
0xfullex wants to merge 2 commits intoleafok:mainfrom
Closed
fix(memory_pool): add thread safety, overflow checks, and double-free protection#850xfullex wants to merge 2 commits intoleafok:mainfrom
0xfullex wants to merge 2 commits intoleafok:mainfrom
Conversation
… protection - Add pthread_mutex to protect all public functions for thread safety - Add integer overflow check before chunk size multiplication - Add double-free detection using magic number at end of node - Align node_size to max_align_t for proper memory alignment - Fix format string argument order in memory_pool_check_node() - Add NULL pointer check in memory_pool_free() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
leafok88
reviewed
Jan 7, 2026
Collaborator
leafok88
left a comment
There was a problem hiding this comment.
This memory pool is used in multi-process application. Therefore, pthread_mutex is not a proper solution for concurrency control.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
pthread_mutexto protect all public functions for thread safetynode_sizetomax_align_tfor proper memory alignmentmemory_pool_check_node()memory_pool_free()Changes
Thread Safety
pthread_mutex_t mutextoMEMORY_POOLstructmemory_pool_init(), destroy inmemory_pool_cleanup()memory_pool_alloc()andmemory_pool_free()Integer Overflow Protection
node_count_per_chunk > SIZE_MAX / node_sizebefore multiplication inmemory_pool_add_chunk()Double-Free Detection
MEMORY_POOL_MAGIC_ALLOCATEDandMEMORY_POOL_MAGIC_FREEmemory_pool_free()to detect double-free attemptsMemory Alignment
align_size()helper function to alignnode_sizetomax_align_tBug Fixes
memory_pool_check_node()log messagep_nodeparameter inmemory_pool_free()Test Plan
🤖 Generated with Claude Code