From: Ilya Lavrenov Date: Tue, 1 Sep 2015 08:40:23 +0000 (+0300) Subject: fixed memory leak in GBTrees X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~2262^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d77d697efd113e5d912ae7136f79088d6363eab;p=platform%2Fupstream%2Fopencv.git fixed memory leak in GBTrees --- diff --git a/modules/ml/src/gbt.cpp b/modules/ml/src/gbt.cpp index 0ebe19e..e41d6c2 100644 --- a/modules/ml/src/gbt.cpp +++ b/modules/ml/src/gbt.cpp @@ -1274,13 +1274,18 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *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); @@ -1313,6 +1318,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector *resp ) err = err / (float)n; } + if (needsFreeing) + delete[]pred_resp; + return err; }