memory leak in MSER algorithm (Bug #4379)


Added by Haojin Yang almost 10 years ago. Updated over 9 years ago.


Status:New Start date:2015-06-04
Priority:Blocker Due date:
Assignee:Maria Dimashova % Done:

0%

Category:features2d
Target version:3.0
Affected version:branch 'master' (3.0-dev) Operating System:Linux
Difficulty:Medium HW Platform:x64
Pull request:

Description

This bug does not always occur. An image has been attached which will cause memory leak when I do the following:

vector<vector<Point> > contours;
vector<Rect> boxes;

Mat gray_im = imread("memtest.jpg", 0);//use grayscale image

Ptr<MSER> mser = MSER::create(21,(int)(0.00002*gray_im.cols*gray_im.rows),(int)(0.05*gray_im.cols*gray_im.rows),1,0.7); 

//here the memory leak will be caused
mser->detectRegions(gray, contours, boxes);


memtest.jpg (56.5 kB) Haojin Yang, 2015-06-04 10:11 am


History

Updated by Haojin Yang almost 10 years ago

I have found the problem is within this function:
void pass( const Mat& img, vector<vector<Point> >& msers, vector<Rect>& bboxvec,
Size size, const int* level_size, int mask );

once a pixel component tries to set the next pixel component.
I added this small check, and found that for this image there will be many pixel items pointed to itself.
Of course this will result in infinite loop in the comptr->capture(....).
But I'm not sure what way to fix this problem is the optimal.
I would be better that someone fixing this who is more familiar with the algorithm.

// add a pixel to the pixel list
if( comptr->tail ){
if(comptr->tail == ptrofs){
printf("pointer to itself, %d\n", ptrofs);
}
ptr0[comptr->tail].setNext(ptrofs);
}

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/5009

Also available in: Atom PDF