@@ -614,8 +614,10 @@ static void free_currents() {
614614 for (i = 0 ; i < _memb_count; i++) {
615615 for (j = 0 ; j < _memb_species_count[i]; j++) {
616616 free (_memb_cur_mapped[i][j]);
617+ free (_memb_cur_mapped_ecs[i][j]);
617618 }
618619 free (_memb_cur_mapped[i]);
620+ free (_memb_cur_mapped_ecs[i]);
619621 }
620622 _memb_cur_ptrs.clear ();
621623 free (_memb_cur_mapped);
@@ -973,6 +975,8 @@ extern "C" NRN_EXPORT void register_rate(int nspecies,
973975 react->flux = (double **) malloc (react->icsN * sizeof (double *));
974976 for (i = 0 ; i < react->icsN ; i++)
975977 react->flux [i] = (double *) malloc (react->num_regions * sizeof (double ));
978+ } else {
979+ react->flux = NULL ;
976980 }
977981 react->states_for_reaction = (double **) malloc (react->num_species * sizeof (double *));
978982 react->states_for_reaction_dx = (double **) malloc (react->num_species * sizeof (double *));
@@ -1015,20 +1019,22 @@ extern "C" NRN_EXPORT void clear_rates() {
10151019 if (react->vptrs != NULL )
10161020 free (react->vptrs );
10171021 for (i = 0 ; i < react->num_segments ; i++) {
1018- for (j = 0 ; j < react->num_species ; j++) {
1022+ for (j = 0 ; j < react->num_species + react-> num_params ; j++) {
10191023 free (react->state_idx [i][j]);
10201024 }
10211025 free (react->state_idx [i]);
10221026
10231027 if (react->num_ecs_species + react->num_ecs_params > 0 ) {
10241028 free (react->ecs_state [i]);
1029+ free (react->ecs_index [i]);
10251030 }
10261031 }
1032+ free (react->state_idx );
10271033 if (react->num_ecs_species + react->num_ecs_params > 0 ) {
10281034 free (react->ecs_index );
10291035 free (react->ecs_state );
1030- free (react->state_idx );
10311036 free (react->ecs_offset_index );
1037+ free (react->ecs_grid );
10321038 }
10331039 if (react->num_mult > 0 ) {
10341040 for (i = 0 ; i < react->num_mult ; i++)
@@ -1040,7 +1046,7 @@ extern "C" NRN_EXPORT void clear_rates() {
10401046
10411047 if (react->num_mult > 0 )
10421048 free (react->mc_mult );
1043- if (_membrane_flux ) {
1049+ if (react-> flux != NULL ) {
10441050 for (i = 0 ; i < react->icsN ; i++)
10451051 free (react->flux [i]);
10461052 free (react->flux );
@@ -1483,7 +1489,8 @@ void get_reaction_rates(ICSReactions* react, double* states, double* rates, doub
14831489 react->ecs_params_for_reaction [k] = NAN ;
14841490 }
14851491 }
1486- memset (react->ecs_result , 0 , react->num_ecs_species * sizeof (double ));
1492+ if (react->num_ecs_species > 0 )
1493+ memset (react->ecs_result , 0 , react->num_ecs_species * sizeof (double ));
14871494
14881495 for (i = 0 ; i < react->num_mult ; i++) {
14891496 react->mc_mult [i] = react->mc_multiplier [i][segment];
0 commit comments