I am improving an xgboost application coded in C++. I am using the C version (the application was coded in C++, but it uses the xgboost C version).
In the application, I find many calls to this function (I put it with its parameters declarations):
char const config[] =
"{"training": false, "type": 0, "
""iteration_begin": 0, "iteration_end": 0, "strict_shape": false}";
/* Shape of output prediction */
uint64_t const* out_shape;
/* Dimension of output prediction */
uint64_t out_dim;
/* Pointer to a thread local contiguous array, assigned in prediction function. */
float const* out_result = NULL;
safe_xgboost(
XGBoosterPredictFromDMatrix(booster, dmatrix, config, &out_shape, &out_dim, &out_result));
This code snippet was directly taken from the c_api tutorial of xgboost.
As can be seen, there are two pointer declarations: out_shape
and out_result
. Now, this code does not allocate memory for those pointers. I suppose that their allocation is made by xgboost.
Also, my code uses this pattern many times and works well.
My doubt is how to dispose of the memory used by those pointers. If I try to get free with the standard free
call, I get a twice-free or a segfault.
The code I am improving seems correct and robust, but I am intrigued by this issue.
Some explanation?