Increase memory safety of MaybeStackArray, MemoryPool and MaybeStackVector

Description

I believe the idiomatic thing for operator=(T&& src) to do is to swap this and src such that values get deallocated appropriately: when the ~T destructor for src is called.

cmemory.h currently has class implementations that release memory in ways that make using them harder: MaybeStackArray's operator= deallocates its memory, which means MemoryPool does not get the opportunity to take care of deallocating instances of T* in its destructor if values were changed via an operator=.

Activity

Show:
Hugo van der Merwe
October 28, 2020, 2:34 PM

Turns out it’s all in MemoryPool: it’s MemoryPool’s destructor that needs to be called for no-longer-needed pointers after “operator=”, so MemoryPool::operator=() needs to swap, not deallocate.

Fixed
Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Hugo van der Merwe

Reporter

Hugo van der Merwe

Components

Labels

Priority

medium

Time Needed

Hours

Fix versions