fix(rpp): Fix device memory leak in HIP histogram_equalize overflow path (#9721)
## Motivation
This PR addresses[ issue 735](https://github.com/ROCm/rpp/issues/735) in
ROCm/rpp: in `hip_exec_histogram_equalize_tensor`, when `required_size`
is greater than SCRATCH_BUFFER_SIZE, the function allocates an overflow
buffer, which does not have an associated `hipFree`. This causes a
device memory leak.
## Technical Details
Wrap the overflow buffer with `std::unique_ptr` with a custom deleter
that calls `hipFreeAsync`.
## Test Plan
CTests should pass.
To verify the overflow issue, and fix, forced the use of the overflow
buffer and then called the function repeatedly (see Details). Without
the fix, there was eventually a `hipMalloc` runtime error on trying to
allocate the buffer with status `hipErrorOutOfMemory`. With the fix,
there was no error.
**Details**
Around line 390 in `histogram_equalize.cpp`, temporarily changed the `if
else` on whether to use the preallocated scratch buffer or allocate the
overflow buffer to always allocate the overflow buffer.
Full command for testing the overflow:
`./Tensor_image_hip
$ROCM_PATH/share/rpp/test/TEST_IMAGES/three_images_mixed_src1
$ROCM_PATH/share/rpp/test/TEST_IMAGES/three_images_mixed_src2
/tmp/test_out 0 0 102 0 100000 1 0 0 0 0 3 0 0 0 0 /tmp`
## Test Result
Start 6: rpp_qa_tests_tensor_image_hip_all
1/1 Test #6: rpp_qa_tests_tensor_image_hip_all ... Passed 1313.26 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 1313.26 sec
## Submission Checklist
- [x] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
---------
Co-authored-by: Kiriti Gowda <kiritigowda@gmail.com> D
Danielle Gillai committed
566ca8bb454e70129afb188174e7df61ba79c67e
Parent: 1d384d4
Committed by GitHub <noreply@github.com>
on 8/14/2026, 7:55:38 PM