[opencv] 17/33: fixed memory leaks in modules/features2d/test/test_nearestneighbors.cpp

Mattia Rizzolo mattia at debian.org
Tue Oct 4 17:51:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to annotated tag 2.4.12.2
in repository opencv.

commit 6dcd455ac4cf279b880458a24e055370b61bb1f5
Author: Ilya Lavrenov <ilya.lavrenov at itseez.com>
Date:   Mon Aug 31 17:20:52 2015 +0300

    fixed memory leaks in modules/features2d/test/test_nearestneighbors.cpp
---
 .../features2d/test/test_lshindex_flannbased_matcher.cpp    | 12 +++++++++++-
 modules/features2d/test/test_nearestneighbors.cpp           | 13 ++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/modules/features2d/test/test_lshindex_flannbased_matcher.cpp b/modules/features2d/test/test_lshindex_flannbased_matcher.cpp
index ddc81b0..d1c6ea7 100644
--- a/modules/features2d/test/test_lshindex_flannbased_matcher.cpp
+++ b/modules/features2d/test/test_lshindex_flannbased_matcher.cpp
@@ -303,7 +303,8 @@ public:
     //
     // 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),
         target_accuracy_margin_from_bfmatcher(_accuracy_margin),
         fe(_fe),
@@ -318,6 +319,15 @@ public:
         bfmatcher = new cv::BFMatcher(norm_type_for_bfmatcher);
     }
 
+    virtual ~CV_FeatureDetectorMatcherBaseTest()
+    {
+        if (bfmatcher)
+        {
+            delete bfmatcher;
+            bfmatcher = NULL;
+        }
+    }
+
     //
     // Main Test method
     //
diff --git a/modules/features2d/test/test_nearestneighbors.cpp b/modules/features2d/test/test_nearestneighbors.cpp
index b63bc64..bb1d51b 100644
--- a/modules/features2d/test/test_nearestneighbors.cpp
+++ b/modules/features2d/test/test_nearestneighbors.cpp
@@ -159,7 +159,7 @@ void NearestNeighborTest::run( int /*start_from*/ ) {
 class CV_KDTreeTest_CPP : public NearestNeighborTest
 {
 public:
-    CV_KDTreeTest_CPP() {}
+    CV_KDTreeTest_CPP() : NearestNeighborTest(), tr(NULL) {}
 protected:
     virtual void createModel( const Mat& data );
     virtual int checkGetPoints( const Mat& data );
@@ -244,7 +244,7 @@ void CV_KDTreeTest_CPP::releaseModel()
 class CV_FlannTest : public NearestNeighborTest
 {
 public:
-    CV_FlannTest() {}
+    CV_FlannTest() : NearestNeighborTest(), index(NULL) { }
 protected:
     void createIndex( const Mat& data, const IndexParams& params );
     int knnSearch( Mat& points, Mat& neighbors );
@@ -255,6 +255,9 @@ protected:
 
 void CV_FlannTest::createIndex( const Mat& data, const IndexParams& params )
 {
+    // release previously allocated index
+    releaseModel();
+
     index = new Index( data, params );
 }
 
@@ -321,7 +324,11 @@ int CV_FlannTest::radiusSearch( Mat& points, Mat& neighbors )
 
 void CV_FlannTest::releaseModel()
 {
-    delete index;
+    if (index)
+    {
+        delete index;
+        index = NULL;
+    }
 }
 
 //---------------------------------------

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git



More information about the debian-science-commits mailing list