Skip to content

Conversation

@favreau
Copy link
Collaborator

@favreau favreau commented Feb 9, 2026

Array::operator=(Array&&) overwrote m_data without freeing the old buffer, leaking memory on every ObjectPool erase. The destructor also called cudaMalloc instead of cudaFree for CUDA arrays.

Array::operator=(Array&&) overwrote m_data without freeing the old
buffer, leaking memory on every ObjectPool erase.  The destructor
also called cudaMalloc instead of cudaFree for CUDA arrays.

Co-authored-by: Cursor <[email protected]>
@favreau favreau requested a review from jeffamstutz February 9, 2026 09:13
@tarcila tarcila requested review from Copilot February 9, 2026 13:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes memory management bugs in Array by correctly releasing existing buffers during move-assignment and freeing CUDA-allocated buffers in the destructor.

Changes:

  • Replace incorrect cudaMalloc call in Array::~Array() with cudaFree.
  • Free the existing m_data buffer in Array::operator=(Array&&) before taking ownership of the moved-from buffer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 49 to 51
else
#endif
std::free(m_data);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The destructor unconditionally std::free(m_data) for non-CUDA arrays, but the move-assignment path explicitly avoids freeing MemoryKind::PROXY. If PROXY buffers are not owned (as implied by the new m_kind != MemoryKind::PROXY guard in move-assignment), the destructor should apply the same ownership rule to avoid freeing memory it doesn't own.

Suggested change
else
#endif
std::free(m_data);
else if (kind() != MemoryKind::PROXY)
std::free(m_data);
#else
if (kind() != MemoryKind::PROXY)
std::free(m_data);
#endif

Copilot uses AI. Check for mistakes.
#if TSD_USE_CUDA
if (kind() == MemoryKind::CUDA)
cudaMalloc(&m_data, size() * elementSize());
cudaFree(m_data);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

cudaFree returns a status code. If the project has a CUDA error-checking macro/helper (e.g., CUDA_CHECK), use it here (and likewise in move-assignment) so deallocation failures aren’t silently ignored.

Copilot uses AI. Check for mistakes.
@jeffamstutz
Copy link
Collaborator

LGTM, thanks!

@jeffamstutz jeffamstutz merged commit b76bd83 into NVIDIA:next_release Feb 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants