Skip to content

Fix memory leaks, missing property assignment, null dereferences, and unhandled errors in libmbdb#2

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/search-project-issues
Draft

Fix memory leaks, missing property assignment, null dereferences, and unhandled errors in libmbdb#2
Copilot wants to merge 3 commits intomasterfrom
copilot/search-project-issues

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 4, 2026

Several bugs across the library ranging from critical memory corruption to memory leaks and unhandled failure paths. No existing test infrastructure.

Critical

  • Missing property assignment (backup_file_create_from_record): Loop allocated each prop but never wrote it into properties[i], leaving the array full of garbage pointers — silent corruption on any record with properties.
// Before: prop allocated, configured, then silently dropped
mbdb_record_property_t* prop = malloc(sizeof(mbdb_record_property_t));
// ... fill prop ...
// ← nothing stored, properties[i] is uninitialized

// After
file->mbdb_record->properties[i] = prop;

Memory Leaks

  • mbdb_parse: Four early-return paths allocated mbdb (and sub-fields header, data, records) without freeing on error. Fixed by calling mbdb_free(mbdb) before each early return.
  • backup_open: backup_path leaked when mbdb_open() fails (mbdb_path was freed but backup_path was not).
  • backup_file_create_from_record: file leaked when the mbdb_record malloc fails.
  • mbdb_record_build: data_buf leaked when the size consistency check fails.

Null Pointer Dereferences

  • backup_file_update_hash: Execution fell through after a failed fopen, passing a NULL FILE* to fread. Fixed by returning early after the error.
  • mbdb_record_parse: properties array allocation and each prop allocation were unchecked; a failed malloc immediately dereferenced NULL on the next line. Added null checks with proper cleanup via mbdb_record_free.

Unhandled Error Returns

  • backup_add_file_from_path: file_read() return value was ignored; a read failure left data as garbage passed into backup_file_create_with_data. Fixed by propagating the error.

Minor

  • Removed five unused old_size local variables in mbdb_record setter functions (dead assignments, compiler warnings).
  • Normalized allocation error messages to consistent casing/punctuation ("Allocation error\n").
Original prompt

Search this project for any issues

Copilot AI and others added 2 commits April 4, 2026 18:48
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
Copilot AI requested a review from posixninja April 4, 2026 18:50
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