Fix memory leaks, missing property assignment, null dereferences, and unhandled errors in libmbdb#2
Draft
Fix memory leaks, missing property assignment, null dereferences, and unhandled errors in libmbdb#2
Conversation
…ences, error handling Agent-Logs-Url: https://github.com/OpenJailbreak/libmbdb/sessions/5bac01a3-f7aa-42dd-902e-e6ea02a9a3ba Co-authored-by: posixninja <50025+posixninja@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenJailbreak/libmbdb/sessions/5bac01a3-f7aa-42dd-902e-e6ea02a9a3ba Co-authored-by: posixninja <50025+posixninja@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Search project for any issues
Fix memory leaks, missing property assignment, null dereferences, and unhandled errors in libmbdb
Apr 4, 2026
posixninja
approved these changes
Apr 4, 2026
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.
Several bugs across the library ranging from critical memory corruption to memory leaks and unhandled failure paths. No existing test infrastructure.
Critical
backup_file_create_from_record): Loop allocated eachpropbut never wrote it intoproperties[i], leaving the array full of garbage pointers — silent corruption on any record with properties.Memory Leaks
mbdb_parse: Four early-return paths allocatedmbdb(and sub-fieldsheader,data,records) without freeing on error. Fixed by callingmbdb_free(mbdb)before each early return.backup_open:backup_pathleaked whenmbdb_open()fails (mbdb_pathwas freed butbackup_pathwas not).backup_file_create_from_record:fileleaked when thembdb_recordmallocfails.mbdb_record_build:data_bufleaked when the size consistency check fails.Null Pointer Dereferences
backup_file_update_hash: Execution fell through after a failedfopen, passing a NULLFILE*tofread. Fixed by returning early after the error.mbdb_record_parse:propertiesarray allocation and eachpropallocation were unchecked; a failedmallocimmediately dereferenced NULL on the next line. Added null checks with proper cleanup viambdb_record_free.Unhandled Error Returns
backup_add_file_from_path:file_read()return value was ignored; a read failure leftdataas garbage passed intobackup_file_create_with_data. Fixed by propagating the error.Minor
old_sizelocal variables inmbdb_recordsetter functions (dead assignments, compiler warnings)."Allocation error\n").Original prompt