This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vector_base: fix memory leak in reserve()
Currently, when using reserve() to actually grow the storage in a vector, a new backend storage is allocated, but the old one is never deallocated. A more minor unexpected behavior that also occurred is that the vector would still apply its exponential growth behavior, ie., it when taking a vector of size 3 and calling `.reserve(4)` on it, one would actually end up with a vector of size 6. The logic to allocate the new storage, copy in the existing elements, then destroy the old elements and swap in the new storage (which does to the old storage being destructed and hence deallocated) is, essentially, taken from how `.resize()` works. When growing a vector using `.reserve()`, the new capacity will now be exactly what was specified in the call to `.reserve()`.
- Loading branch information