From 00d9728e4bbc1681857cb981e213e432dceda86a Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 17 Mar 2018 19:03:27 -0700 Subject: [PATCH] Fix memory leak in XGDMatrixCreateFromMat_omp() (#3182) * Fix memory leak in XGDMatrixCreateFromMat_omp() This replaces the array allocated by new with a std::vector. Fixes #3161 --- src/c_api/c_api.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index f9150156d..47d4a9668 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -452,11 +452,8 @@ XGB_DLL int XGDMatrixCreateFromMat_omp(const bst_float* data, // Check for errors in missing elements // Count elements per row (to avoid otherwise need to copy) bool nan_missing = common::CheckNAN(missing); - int *badnan; - badnan = new int[nthread]; - for (int i = 0; i < nthread; i++) { - badnan[i] = 0; - } + std::vector badnan; + badnan.resize(nthread, 0); #pragma omp parallel num_threads(nthread) {