fixed memory leak in GBTrees

This commit is contained in:
Ilya Lavrenov 2015-09-01 11:40:23 +03:00 committed by Dikay900
parent cf0f47f589
commit 1d77d697ef

View File

@ -1274,13 +1274,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);
@ -1313,6 +1318,9 @@ CvGBTrees::calc_error( CvMLData* _data, int type, std::vector<float> *resp )
err = err / (float)n;
}
if (needsFreeing)
delete[]pred_resp;
return err;
}