Skip to content

Commit f10c84d

Browse files
authored
Merge pull request #3515 from asmorkalov:as/find_ellipses_memory
Fixed memory leak in EllipseDetector and Mat addressing
2 parents 4f66f86 + d545bab commit f10c84d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

modules/ximgproc/src/find_ellipses.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,9 @@ void EllipseDetectorImpl::preProcessing(Mat1b &image, Mat1b &dp, Mat1b &dn) {
12721272

12731273
// buffer
12741274
int *magBuffer[3];
1275-
void *buffer = malloc((imgSize.width + 2) * (imgSize.height + 2) +
1276-
(imgSize.width + 2) * 3 * sizeof(int));
1277-
magBuffer[0] = (int *) buffer;
1275+
AutoBuffer<int> buffer((imgSize.width + 2) * (imgSize.height + 2) +
1276+
(imgSize.width + 2) * 3);
1277+
magBuffer[0] = buffer.data();
12781278
magBuffer[1] = magBuffer[0] + imgSize.width + 2;
12791279
magBuffer[2] = magBuffer[1] + imgSize.width + 2;
12801280
uchar *map = (uchar *) (magBuffer[2] + imgSize.width + 2);
@@ -1300,8 +1300,8 @@ void EllipseDetectorImpl::preProcessing(Mat1b &image, Mat1b &dp, Mat1b &dn) {
13001300
// 2 - the pixel does belong to an edge
13011301
for (int i = 0; i <= imgSize.height; i++) {
13021302
int *tmpMag = magBuffer[(i > 0) + 1] + 1;
1303-
const short *tmpDx = (short *) (dx[i]);
1304-
const short *tmpDy = (short *) (dy[i]);
1303+
const short *tmpDx = dx.ptr<short>(i);
1304+
const short *tmpDy = dy.ptr<short>(i);
13051305
uchar *tmpMap;
13061306
int prevFlag = 0;
13071307

@@ -1980,4 +1980,4 @@ void findEllipses(
19801980
Mat(_ellipses).copyTo(ellipses);
19811981
}
19821982
} // namespace ximgproc
1983-
} // namespace cv
1983+
} // namespace cv

0 commit comments

Comments
 (0)