From f8fc40f1acef7894d4f73dc07f4589df48e03d33 Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Fri, 1 Dec 2023 16:02:31 -0500 Subject: [PATCH] fix minor leaks in sample() --- eidos/eidos_functions_values.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eidos/eidos_functions_values.cpp b/eidos/eidos_functions_values.cpp index 22aa1404..c24a5daa 100644 --- a/eidos/eidos_functions_values.cpp +++ b/eidos/eidos_functions_values.cpp @@ -436,7 +436,10 @@ EidosValue_SP Eidos_ExecuteFunction_sample(const std::vector &p_a int64_t weight = weights_int[value_index]; if (weight < 0) + { + free(weights_float_malloced); EIDOS_TERMINATION << "ERROR (Eidos_ExecuteFunction_sample): function sample() requires all weights to be non-negative (" << weight << " supplied)." << EidosTerminate(nullptr); + } weights_float_malloced[value_index] = weight; weights_sum += weight; @@ -447,7 +450,10 @@ EidosValue_SP Eidos_ExecuteFunction_sample(const std::vector &p_a } if (weights_sum <= 0.0) + { + free(weights_float_malloced); EIDOS_TERMINATION << "ERROR (Eidos_ExecuteFunction_sample): function sample() encountered weights summing to <= 0." << EidosTerminate(nullptr); + } // prepare the GSL to draw from the discrete distribution gsl_ran_discrete_t *discrete_draw = gsl_ran_discrete_preproc(x_count, weights_float);