fixed memory leak in GBTrees

This commit is contained in:
Ilya Lavrenov 2015-09-01 11:40:23 +03:00
parent 94cf5430d0
commit 1b8c2589c0

View File

@ -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;
}