fixed memory leaks in modules/features2d/test/test_nearestneighbors.cpp

This commit is contained in:
Ilya Lavrenov 2015-08-31 17:20:52 +03:00
parent 94cf5430d0
commit be499b42d9
2 changed files with 21 additions and 4 deletions

View File

@ -303,7 +303,8 @@ public:
// //
// constructor // constructor
// //
CV_FeatureDetectorMatcherBaseTest(testparam* _tp, double _accuracy_margin, cv::Feature2D* _fe, cv::DescriptorMatcher *_flmatcher, string _flmatchername, int norm_type_for_bfmatcher) : CV_FeatureDetectorMatcherBaseTest(testparam* _tp, double _accuracy_margin, cv::Feature2D* _fe,
cv::DescriptorMatcher *_flmatcher, string _flmatchername, int norm_type_for_bfmatcher) :
tp(_tp), tp(_tp),
target_accuracy_margin_from_bfmatcher(_accuracy_margin), target_accuracy_margin_from_bfmatcher(_accuracy_margin),
fe(_fe), fe(_fe),
@ -318,6 +319,15 @@ public:
bfmatcher = new cv::BFMatcher(norm_type_for_bfmatcher); bfmatcher = new cv::BFMatcher(norm_type_for_bfmatcher);
} }
virtual ~CV_FeatureDetectorMatcherBaseTest()
{
if (bfmatcher)
{
delete bfmatcher;
bfmatcher = NULL;
}
}
// //
// Main Test method // Main Test method
// //

View File

@ -159,7 +159,7 @@ void NearestNeighborTest::run( int /*start_from*/ ) {
class CV_KDTreeTest_CPP : public NearestNeighborTest class CV_KDTreeTest_CPP : public NearestNeighborTest
{ {
public: public:
CV_KDTreeTest_CPP() {} CV_KDTreeTest_CPP() : NearestNeighborTest(), tr(NULL) {}
protected: protected:
virtual void createModel( const Mat& data ); virtual void createModel( const Mat& data );
virtual int checkGetPoints( const Mat& data ); virtual int checkGetPoints( const Mat& data );
@ -244,7 +244,7 @@ void CV_KDTreeTest_CPP::releaseModel()
class CV_FlannTest : public NearestNeighborTest class CV_FlannTest : public NearestNeighborTest
{ {
public: public:
CV_FlannTest() {} CV_FlannTest() : NearestNeighborTest(), index(NULL) { }
protected: protected:
void createIndex( const Mat& data, const IndexParams& params ); void createIndex( const Mat& data, const IndexParams& params );
int knnSearch( Mat& points, Mat& neighbors ); int knnSearch( Mat& points, Mat& neighbors );
@ -255,6 +255,9 @@ protected:
void CV_FlannTest::createIndex( const Mat& data, const IndexParams& params ) void CV_FlannTest::createIndex( const Mat& data, const IndexParams& params )
{ {
// release previously allocated index
releaseModel();
index = new Index( data, params ); index = new Index( data, params );
} }
@ -320,8 +323,12 @@ int CV_FlannTest::radiusSearch( Mat& points, Mat& neighbors )
} }
void CV_FlannTest::releaseModel() void CV_FlannTest::releaseModel()
{
if (index)
{ {
delete index; delete index;
index = NULL;
}
} }
//--------------------------------------- //---------------------------------------