Skip to content

Commit b01e6a7

Browse files
authored
Merge pull request #3999 from incubus-ank:fix/cuda_fast_detectAsync_memory_leak
Add missing cudaFree #3999 I found missing memory cudaFree in cv::cuda::FAST_Impl::detectAsync() I created an issue, but did not receive a response. #3994 ### Pull Request Readiness Checklist - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
1 parent 095981c commit b01e6a7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/cudafeatures2d/src/fast.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace
6666
{
6767
public:
6868
FAST_Impl(int threshold, bool nonmaxSuppression, int max_npoints);
69+
~FAST_Impl();
6970

7071
virtual void detect(InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask);
7172
virtual void detectAsync(InputArray _image, OutputArray _keypoints, InputArray _mask, Stream& stream);
@@ -95,6 +96,12 @@ namespace
9596
FAST_Impl::FAST_Impl(int threshold, bool nonmaxSuppression, int max_npoints) :
9697
threshold_(threshold), nonmaxSuppression_(nonmaxSuppression), max_npoints_(max_npoints)
9798
{
99+
cudaSafeCall( cudaMalloc(&d_counter, sizeof(unsigned int)) );
100+
}
101+
102+
FAST_Impl::~FAST_Impl()
103+
{
104+
cudaSafeCall( cudaFree(d_counter) );
98105
}
99106

100107
void FAST_Impl::detect(InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask)
@@ -116,8 +123,6 @@ namespace
116123
{
117124
using namespace cv::cuda::device::fast;
118125

119-
cudaSafeCall( cudaMalloc(&d_counter, sizeof(unsigned int)) );
120-
121126
const GpuMat img = _image.getGpuMat();
122127
const GpuMat mask = _mask.getGpuMat();
123128

@@ -165,8 +170,6 @@ namespace
165170
kpLoc.colRange(0, count).copyTo(locRow, stream);
166171
keypoints.row(1).setTo(Scalar::all(0), stream);
167172
}
168-
169-
cudaSafeCall( cudaFree(d_counter) );
170173
}
171174

172175
void FAST_Impl::convert(InputArray _gpu_keypoints, std::vector<KeyPoint>& keypoints)

0 commit comments

Comments
 (0)