Skip to content

Fix double destroy in vector#7331

Merged
davebayer merged 2 commits intoNVIDIA:mainfrom
miscco:fix_double_delete_vector
Jan 23, 2026
Merged

Fix double destroy in vector#7331
davebayer merged 2 commits intoNVIDIA:mainfrom
miscco:fix_double_delete_vector

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jan 23, 2026

We were not resetting the vector::m_size member after destroying the old storage, only vector::m_storage::m_size. Then in range_assign we would call m_storage.destroy(begin(), end()); but end() takes into account vector::m_size and not vector::m_storage::m_size.

Consequently we would try to delete the old elements again, even if the storage was already deallocated, passing a nullptr to destroy_at

This started to fail because with the rework of allocator_traits in another PR we are actually checking in cuda::std::__destroy_at whether the passed pointer is valid.

We were not resetting the `vector::m_size` member after destroying the old storage, only `vector::m_storage::m_size`.
Then in `range_assign` we would call `m_storage.destroy(begin(), end());` but `end()` takes into account `vector::m_size` and not `vector::m_storage::m_size`.

Consequently we would try to delete the old elements again, even if the storage was already deallocated, passing a `nullptr` to `destroy_at`

This started to fail because with the rework of `allocator_traits` in another PR we are actually checking in `cuda::std::__destroy_at` whether the passed pointer is valid.
@miscco miscco requested a review from a team as a code owner January 23, 2026 09:07
@miscco miscco requested a review from elstehle January 23, 2026 09:07
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 23, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Jan 23, 2026
@miscco miscco changed the title Fix double delete in vector Fix double destroy in vector Jan 23, 2026
@davebayer davebayer enabled auto-merge (squash) January 23, 2026 09:44
@github-project-automation github-project-automation bot moved this from In Review to In Progress in CCCL Jan 23, 2026
Comment on lines 169 to 175
m_storage.propagate_allocator(v.m_storage);
if constexpr (thrust::detail::allocator_traits<Alloc>::propagate_on_container_copy_assignment::value)
{
if (m_allocator != other.m_allocator)
{
m_size = 0;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since m_storage.propagate_allocator changes this->m_allocator, we need to move this check before it.

@miscco miscco force-pushed the fix_double_delete_vector branch 2 times, most recently from 88600bf to 0135e55 Compare January 23, 2026 10:41
@miscco miscco force-pushed the fix_double_delete_vector branch from 0135e55 to 679ba42 Compare January 23, 2026 10:42
@github-project-automation github-project-automation bot moved this from In Progress to In Review in CCCL Jan 23, 2026
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

🥳 CI Workflow Results

🟩 Finished in 4h 53m: Pass: 100%/86 | Total: 3d 00h | Max: 2h 29m | Hits: 73%/125754

See results here.

@davebayer davebayer merged commit 8faa9a6 into NVIDIA:main Jan 23, 2026
194 of 198 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants