[rocsparse] Fix memory leak of nnzsplit starting_ids in csrmv info#6595
Merged
kliegeois merged 1 commit intoROCm:developfrom Apr 21, 2026
Merged
[rocsparse] Fix memory leak of nnzsplit starting_ids in csrmv info#6595kliegeois merged 1 commit intoROCm:developfrom
kliegeois merged 1 commit intoROCm:developfrom
Conversation
…:clear() Add clear() and destructor to _rocsparse_nnzsplit_info (matching the existing pattern for adaptive_info and lrb_info), and call this->nnzsplit.clear() from _rocsparse_csrmv_info::clear(). The starting_ids buffer allocated via rocsparse_hipMallocAsync in csrmv_template_nnzsplit was never freed when clear() was called. starting_block_ids points into the same allocation, so only one free is needed.
jsandham
approved these changes
Apr 20, 2026
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (47.50%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6595 +/- ##
===========================================
+ Coverage 66.79% 66.82% +0.03%
===========================================
Files 2255 2256 +1
Lines 325081 324970 -111
Branches 41532 41510 -22
===========================================
+ Hits 217132 217145 +13
+ Misses 93289 93161 -128
- Partials 14660 14664 +4
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
ntrost57
approved these changes
Apr 21, 2026
assistant-librarian Bot
pushed a commit
to ROCm/rocSPARSE
that referenced
this pull request
Apr 21, 2026
[rocsparse] Fix memory leak of nnzsplit starting_ids in csrmv info (#6595) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What changed and why `_rocsparse_csrmv_info::clear()` frees the `adaptive` and `lrb` sub-info device buffers but never frees `nnzsplit.starting_ids`, the device buffer allocated in `rocsparse_csrmv_template_nnzsplit.cpp`. This causes a device memory leak every time csrmv info is cleared or destroyed. The fix adds a destructor and `clear()` method to `_rocsparse_nnzsplit_info`, matching the existing pattern used by `_rocsparse_adaptive_info` and `_rocsparse_lrb_info`, and calls `this->nnzsplit.clear()` from `_rocsparse_csrmv_info::clear()`. `starting_block_ids` is an interior pointer into the `starting_ids` allocation (`&temp_buffer_j[requiredBlocks + 1]`), so only `starting_ids` needs to be freed. ## API changes / backward compatibility None. This is an internal-only change; no public API is affected. ## Performance impact This is a memory leak fix. No performance regression is expected — the only added cost is freeing a device allocation that was previously leaked. ## Testing The existing csrmv test suite exercises the nnzsplit code path and validates functional correctness. The leak was silent (no crash or wrong result), so no new test case is added. The fix can be verified with a memory sanitizer or memstat-enabled build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
_rocsparse_csrmv_info::clear()frees theadaptiveandlrbsub-info device buffers but never freesnnzsplit.starting_ids, the device buffer allocated inrocsparse_csrmv_template_nnzsplit.cpp. This causes a device memory leak every time csrmv info is cleared or destroyed.The fix adds a destructor and
clear()method to_rocsparse_nnzsplit_info, matching the existing pattern used by_rocsparse_adaptive_infoand_rocsparse_lrb_info, and callsthis->nnzsplit.clear()from_rocsparse_csrmv_info::clear().starting_block_idsis an interior pointer into thestarting_idsallocation (&temp_buffer_j[requiredBlocks + 1]), so onlystarting_idsneeds to be freed.API changes / backward compatibility
None. This is an internal-only change; no public API is affected.
Performance impact
This is a memory leak fix. No performance regression is expected — the only added cost is freeing a device allocation that was previously leaked.
Testing
The existing csrmv test suite exercises the nnzsplit code path and validates functional correctness. The leak was silent (no crash or wrong result), so no new test case is added. The fix can be verified with a memory sanitizer or memstat-enabled build.