Skip to content

Fix memory leaks in avm_open() - #3

Open
gzagaris wants to merge 1 commit into
masterfrom
bugfix/gzagaris/fix-memory-leaks
Open

Fix memory leaks in avm_open()#3
gzagaris wants to merge 1 commit into
masterfrom
bugfix/gzagaris/fix-memory-leaks

Conversation

@gzagaris

Copy link
Copy Markdown
Member

AddressSanitizer running on Mint's AVMesh unit tests exposed memory leaks in avm_open() when attempting to open invalid AVMesh files. This change delays avmesh_file allocation until after the file is successfully opened and its prefix metadata is read, ensuring early error paths clean up consistently both before and after registration.

AddressSanitizer running on Mint's AVMesh unit tests
exposed memory leaks in avm_open() when attempting to
open invalid AVMesh files. This change delays avmesh_file
allocation until after the file is successfully opened and
its prefix metadata is read, ensuring early error paths
clean up consistently both before and after registration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts avm_open() error-handling and allocation order to prevent resource leaks when opening invalid/non-AVMesh files, as detected by AddressSanitizer in unit tests.

Changes:

  • Delay avmesh_file allocation/registration until after fopen() succeeds and the file_id_prefix metadata is successfully read.
  • Standardize early-exit cleanup by explicitly fclose()ing on file_id_prefix read failure.
  • Replace manual delete cleanup on rev open failures with avm_close().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/avmesh.cpp
Comment on lines +52 to +58
// allocate an avmesh_file instance
avmesh_file *avf = new avmesh_file;
avf->rev0 = NULL;
avf->rev1 = NULL;
avf->rev2 = NULL;
avf->formatRevision = -1;
file_list[file_counter] = avf;
Comment thread src/avmesh.cpp
Comment on lines 68 to 71
if (rev0::avm_open(avf->rev0, id)) {
delete avf->rev0;
delete avf;
avm_close(file_counter);
return 1;
}
Comment thread src/avmesh.cpp
if (rev1::avm_open(avf->rev1, id)) {
delete avf->rev1;
delete avf;
if (rev1::avm_open(avf->rev1, id)) {
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