Skip to content

Reclaim objects left behind by an interrupted pointer load - #365

Open
gennaroprota wants to merge 1 commit into
developfrom
fix/reclaim-pointer-when-load-interrupted
Open

Reclaim objects left behind by an interrupted pointer load#365
gennaroprota wants to merge 1 commit into
developfrom
fix/reclaim-pointer-when-load-interrupted

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

delete_created_pointers() only freed objects whose load had run to completion, so a load cut short by an exception leaked the object it had already created. It also freed objects an owning smart pointer had taken over, double freeing the elements of a vector<shared_ptr> whether the load failed part way or succeeded outright.

An object becomes reclaimable once its constructor has run, and only when no enclosing created object owns it: freeing that one runs the destructors of the objects below it rather than freeing them twice. An adopting shared_ptr, unique_ptr or scoped_ptr takes the object over and the archive then leaves it alone.

Fixes #260.

`delete_created_pointers()` only freed objects whose load had run to
completion, so a load cut short by an exception leaked the object it had
already created.  It also freed objects an owning smart pointer had
taken over, double freeing the elements of a `vector<shared_ptr>`
whether the load failed part way or succeeded outright.

An object becomes reclaimable once its constructor has run, and only
when no enclosing created object owns it: freeing that one runs the
destructors of the objects below it rather than freeing them twice. An
adopting `shared_ptr`, `unique_ptr` or `scoped_ptr` takes the object
over and the archive then leaves it alone.

Fixes #260.
@gennaroprota
gennaroprota force-pushed the fix/reclaim-pointer-when-load-interrupted branch from e43401c to 5a4adc3 Compare August 6, 2026 10:05
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.

Memory leak during failed xml deserialization

1 participant