Skip to content

<deque>: Properly destroy (fancy) pointers to blocks in the internal map - #2775

Merged
Stephan T. Lavavej (StephanTLavavej) merged 13 commits into
microsoft:mainfrom
frederick-vs-ja:deque-block-ptrs
Jun 12, 2022
Merged

<deque>: Properly destroy (fancy) pointers to blocks in the internal map#2775
Stephan T. Lavavej (StephanTLavavej) merged 13 commits into
microsoft:mainfrom
frederick-vs-ja:deque-block-ptrs

Conversation

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

The internal map array is fully constructed, so it should also be fully destroyed before deallocation.

Fixes #2769.

The map array is fully constructed just after allocation, so it should be fully destroyed before deallocation.
@frederick-vs-ja
A. Jiang (frederick-vs-ja) requested a review from a team as a code owner June 9, 2022 06:29
Comment thread stl/inc/deque Outdated
Comment thread tests/std/tests/GH_002769_handle_deque_block_pointers/test.cpp Outdated

size_t fancy_counter{};

template <class T>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That is some pretty extensive work needed for a small test.

I am wondering whether it would make sense to reuse that machinery and test all containers for internal memory leaks?

Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
@CaseyCarter Casey Carter (CaseyCarter) added the bug Something isn't working label Jun 9, 2022
Comment thread tests/std/tests/GH_002769_handle_deque_block_pointers/test.cpp Outdated
Comment thread tests/std/tests/GH_002769_handle_deque_block_pointers/test.cpp Outdated
Comment thread tests/std/tests/GH_002769_handle_deque_block_pointers/test.cpp Outdated
Comment thread tests/std/tests/GH_002769_handle_deque_block_pointers/test.cpp Outdated
Comment thread stl/inc/deque Outdated
Also place _Mysize() before _Newsize for consistency
Comment thread stl/inc/deque
void _Construct_n(size_type _Count, const _Ty& _Val) { // construct from _Count * _Val
_Tidy_guard<deque> _Guard{this};
for (; 0 < _Count; --_Count) {
for (; _Count > 0; --_Count) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No change requested: We generally try to avoid mixing unrelated cleanups into behavioral changes (as this increases the difficulty of reviewing and understanding source history). This isn't an ironclad rule - we're human and it's easier to fold changes into an existing PR, so a small amount of cleanup can be fine. In this case I think it's fine, but I wanted to mention it.

Comment on lines +140 to +142
friend bool operator==(const counting_ptr& lhs, const counting_ptr& rhs) = default;

friend auto operator<=>(const counting_ptr& lhs, const counting_ptr& rhs) = default;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No change requested: In product code, we conventionally don't name parameters of defaulted functions. On the other hand, in test code we're somewhat less rigorous about conventions. On the third hand, operator=(const counting_ptr&) didn't name its parameter, which is an argument for being locally consistent here. On the fourth and final hand, this isn't worth resetting testing. 😹

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej

Copy link
Copy Markdown
Member

I've resolved a trivial adjacent-add merge conflict in tests/std/test.lst.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 9947dd9 into microsoft:main Jun 12, 2022
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for fixing this correctness bug! 🐞 🎉 😸

@frederick-vs-ja
A. Jiang (frederick-vs-ja) deleted the deque-block-ptrs branch June 12, 2022 11:43
Igor Zhukov (fsb4000) pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
…l map (microsoft#2775)

Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<deque>: For allocators where allocator_traits<T>::pointer is an object, destructors aren't always called

4 participants