[opencv] 22/33: fixed memory leak in GBTrees

Mattia Rizzolo mattia at debian.org
Tue Oct 4 17:51:05 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 54693b3fa70c90acffbf9e13d135c5cc0a4665bd
Author: Ilya Lavrenov <ilya.lavrenov at itseez.com>
Date:   Tue Sep 1 11:40:23 2015 +0300

    fixed memory leak in GBTrees
    
    (cherry picked from commit 1b8c2589c057f862008cd1a3be5c8802b7bf1994)
---
 modules/ml/src/gbt.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/modules/ml/src/gbt.cpp b/modules/ml/src/gbt.cpp
index 131eb43..aeaf669 100644
--- a/modules/ml/src/gbt.cpp
+++ b/modules/ml/src/gbt.cpp
@@ -1292,13 +1292,18 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
         return -FLT_MAX;
 
     float* pred_resp = 0;
+    bool needsFreeing = false;
+
     if (resp)
     {
         resp->resize(n);
         pred_resp = &((*resp)[0]);
     }
     else
+    {
         pred_resp = new float[n];
+        needsFreeing = true;
+    }
 
     Sample_predictor predictor = Sample_predictor(this, pred_resp, _data->get_values(),
             _data->get_missing(), _sample_idx);
@@ -1331,6 +1336,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
         err = err / (float)n;
     }
 
+    if (needsFreeing)
+        delete[]pred_resp;
+
     return err;
 }
 

-- 
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