Deallocate in BPatch destructor#644
Deallocate in BPatch destructor#644jrood-nrel wants to merge 7 commits intoAMReX-Combustion:developmentfrom
Conversation
baperry2
left a comment
There was a problem hiding this comment.
It does look like this was memory leaking due to not actually deallocating the boundary patch data.
I also removed some unused pointers related to bpatches and updates the test that is supposed to include this capability (the wrong input file had the inputs).
There was a problem hiding this comment.
Pull request overview
This PR updates boundary patch lifetime management so patch-related allocations are cleaned up automatically, and updates the TripleFlame regtest input to exercise boundary-patch mass-fraction flux diagnostics and active control.
Changes:
- Call
BPatch::deallocate()fromBPatch’s destructor. - Remove unused
boundary_patches/boundary_patches_draw pointers fromPeleLMeX.H. - Update
Exec/RegTests/TripleFlame/tripleflame-2d.inpto enable patch MFR diagnostics and active control parameters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
Source/PeleLMeX_BPatch.H |
Makes BPatch destructor free its host/device allocations via deallocate(). |
Source/PeleLMeX.H |
Removes unused raw-pointer members related to boundary patches. |
Exec/RegTests/TripleFlame/tripleflame-2d.inp |
Turns on patch MFR diagnostics and active control for the TripleFlame input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public: | ||
| BPatch() = default; | ||
| ~BPatch() = default; | ||
| ~BPatch() { deallocate(); } |
There was a problem hiding this comment.
Adding a destructor that calls deallocate() makes BPatch responsible for freeing raw host/device allocations, but deallocate() does not reset m_host_allocated/m_device_allocated or null out the pointers. If deallocate() is ever called explicitly (or is called twice due to future refactors), the destructor will attempt to free the same pointers again, causing a double-free. Make deallocate() idempotent by clearing the flags and pointers after freeing (and consider guarding frees with nullptr checks as well).
| ~BPatch() { deallocate(); } | |
| ~BPatch() = default; |
| BPatch() = default; | ||
| ~BPatch() = default; | ||
| ~BPatch() { deallocate(); } | ||
|
|
There was a problem hiding this comment.
With a user-defined destructor freeing internal raw pointers, the implicitly-generated copy/move constructor and assignment operators will perform shallow copies of m_bpdata_d and the host pointers, leading to double-free/use-after-free if a BPatch is ever copied or moved by value. Explicitly delete copy/move operations, or implement proper move semantics (and deep-copy if copying is intended).
| BPatch(const BPatch&) = delete; | |
| BPatch& operator=(const BPatch&) = delete; | |
| BPatch(BPatch&&) = delete; | |
| BPatch& operator=(BPatch&&) = delete; |
No description provided.