From 8f16a4340ce9c71f23d7cb7e0b23a0ccdc8e71af Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Tue, 4 Jun 2024 09:40:19 +0200 Subject: [PATCH] No need to precheck for ptr!=0 for free (#2890) From https://linux.die.net/man/3/free: If ptr is NULL, no operation is performed. --- src/nrnpython/grids.h | 5 ----- src/nrnpython/rxd.cpp | 4 ++-- src/nrnpython/rxd_extracellular.cpp | 34 ++++++++++++++--------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 1f5e9f1042..0d43a3f1fe 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -11,11 +11,6 @@ and Flux_pair structs and their respective functions #include "nrn_pyhocobject.h" #include "nrnwrap_Python.h" -#define SAFE_FREE(ptr) \ - { \ - if ((ptr) != NULL) \ - free(ptr); \ - } #define IDX(x, y, z) ((z) + (y) *g->size_z + (x) *g->size_z * g->size_y) #define INDEX(x, y, z) ((z) + (y) *grid->size_z + (x) *grid->size_z * grid->size_y) #define ALPHA(x, y, z) (g->get_alpha(g->alpha, IDX(x, y, z))) diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index c4dea01f55..04f123e1e2 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -988,10 +988,10 @@ extern "C" void clear_rates() { } free(react->state_idx); - SAFE_FREE(react->ecs_state); + free(react->ecs_state); prev = react; react = react->next; - SAFE_FREE(prev); + free(prev); } _reactions = NULL; /*clear extracellular reactions*/ diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index c297b65be8..6c4e910800 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -35,10 +35,10 @@ static void ecs_refresh_reactions(const int n) { int k; if (threaded_reactions_tasks != NULL) { for (k = 0; k < NUM_THREADS; k++) { - SAFE_FREE(threaded_reactions_tasks[k].onset); - SAFE_FREE(threaded_reactions_tasks[k].offset); + free(threaded_reactions_tasks[k].onset); + free(threaded_reactions_tasks[k].offset); } - SAFE_FREE(threaded_reactions_tasks); + free(threaded_reactions_tasks); } threaded_reactions_tasks = create_threaded_reactions(n); } @@ -61,13 +61,13 @@ void clear_rates_ecs(void) { ECS_Grid_node* g; for (r = ecs_reactions; r != NULL; r = tmp) { - SAFE_FREE(r->species_states); + free(r->species_states); if (r->subregion) { - SAFE_FREE(r->subregion); + free(r->subregion); } tmp = r->next; - SAFE_FREE(r); + free(r); } ecs_reactions = NULL; @@ -416,12 +416,12 @@ void* ecs_do_reactions(void* dataptr) { } } - SAFE_FREE(states_cache); - SAFE_FREE(states_cache_dx); - SAFE_FREE(params_cache); - SAFE_FREE(results_array); - SAFE_FREE(results_array_dx); - SAFE_FREE(mc_mults_array); + free(states_cache); + free(states_cache_dx); + free(params_cache); + free(results_array); + free(results_array_dx); + free(mc_mults_array); if (stop) return NULL; @@ -537,11 +537,11 @@ void* ecs_do_reactions(void* dataptr) { } } - SAFE_FREE(states_cache); - SAFE_FREE(states_cache_dx); - SAFE_FREE(params_cache); - SAFE_FREE(results_array); - SAFE_FREE(results_array_dx); + free(states_cache); + free(states_cache_dx); + free(params_cache); + free(results_array); + free(results_array_dx); if (stop) return NULL;