Fix memory allocator mismatch in error message handling#3
Merged
Conversation
Replace strdup() calls with sqlite3_mprintf() to ensure consistent memory management. Error messages allocated with strdup() (standard malloc) were being freed with sqlite3_free(), causing crashes. Fixes agentflare-ai#2
Contributor
|
@dirtyfilthy Our first contribution! Thanks I'm actually working on the memory leaks right now in the new MERGE feature. Thanks for knocking this out! |
gabewillen
approved these changes
Nov 14, 2025
gabewillen
pushed a commit
that referenced
this pull request
Nov 17, 2025
Replace strdup() calls with sqlite3_mprintf() to ensure consistent memory management. Error messages allocated with strdup() (standard malloc) were being freed with sqlite3_free(), causing crashes. Fixes #2
7 tasks
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.
Replace strdup() calls with sqlite3_mprintf() to ensure consistent memory management. Error messages allocated with strdup() (standard malloc) were being freed with sqlite3_free(), causing crashes.
Fixes #2
Description
This PR fixes a memory allocator mismatch bug that caused crashes when executing invalid Cypher queries. Error messages were allocated using
strdup()(standard C librarymalloc()) but freed usingsqlite3_free()(SQLite's allocator), resulting infree(): invalid pointercrashes.Related Issues
Closes #2
Type of Change
Changes Made
strdup("Query string is NULL")withsqlite3_mprintf("%s", "Query string is NULL")at line 172strdup("Failed to create lexer")withsqlite3_mprintf("%s", "Failed to create lexer")at line 177strdup(pParser->zErrorMsg)withsqlite3_mprintf("%s", pParser->zErrorMsg)at line 184!pParser->pAst &&check)Testing
make test)Test Evidence
Before fix:
Valgrind output (before fix):
After fix:
Documentation
Checklist
Breaking Changes
N/A
Performance Impact
Screenshots / Examples
Minimal reproduction (before fix):
After fix:
Additional Context
The issue was identified using Valgrind, which clearly showed the allocator mismatch:
strdup()(standardmalloc())sqlite3_free()(SQLite's allocator)The fix ensures all error message allocations use SQLite's allocator (
sqlite3_mprintf) which is compatible withsqlite3_free().Reviewer Notes
Please verify:
strdup()replacements are correct!pParser->pAst &&) is appropriateFor Maintainers: