Fixed memory all memory leaks from mytest.

Modified ss_r to run on Windows.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6475 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2012-04-13 17:08:59 +00:00
parent bf96306cba
commit 8e0844ed26
7 changed files with 45 additions and 8 deletions

View File

@ -631,6 +631,7 @@ void Phreeqc::init(void)
pitzer_pe = FALSE;
count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants
x0_moles = NULL;
/*
* SIT
*/
@ -746,6 +747,7 @@ void Phreeqc::init(void)
/* kinetics.c */
m_original = NULL;
m_temp = NULL;
rk_moles = NULL;
/* pitzer.c */
A0 = 0;

View File

@ -1709,6 +1709,7 @@ public:
cxxPPassemblage *cvode_pp_assemblage_save;
LDBLE *m_original;
LDBLE *m_temp;
LDBLE *rk_moles;
int set_and_run_attempt;
/* model.cpp ------------------------------- */

View File

@ -4392,6 +4392,7 @@ dump_netpath_pat(struct inverse *inv_ptr)
fprintf(netpath_file, "%d. Solution %d\n", count_inverse_models,
solution_ptr_orig->Get_n_user());
}
description = (char *) free_check_null(description);
/* bookkeeping */
count_pat_solutions++;

View File

@ -260,7 +260,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
int l_bad, step_bad, step_ok;
int n_reactions;
LDBLE h, h_old, h_sum;
LDBLE *rk_moles;
LDBLE l_error, error_max, safety, moles_max, moles_reduction;
cxxKinetics *kinetics_ptr;
int equal_rate, zero_rate;
@ -293,10 +292,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
if (kinetics_ptr == NULL)
return (OK);
n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size();
rk_moles =
(LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE));
if (rk_moles == NULL)
malloc_error();
rk_moles = (LDBLE *) free_check_null(rk_moles);
rk_moles = (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE));
if (rk_moles == NULL) malloc_error();
/*if (use_mix != NOMIX) last_model.force_prep = TRUE; */
set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction);
@ -1388,6 +1386,16 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver,
pr.use = TRUE;
sum_species();
print_all();
if (pp_assemblage_save != NULL)
{
delete pp_assemblage_save;
pp_assemblage_save = NULL;
}
if (ss_assemblage_save != NULL)
{
delete ss_assemblage_save;
ss_assemblage_save = NULL;
}
error_string = sformatf(
"Numerical method failed on all combinations of convergence parameters");
error_msg(error_string, STOP);
@ -2528,12 +2536,12 @@ store_get_equi_reactants(int l, int kin_end)
}
}
k = count_pp + count_ss + count_pg;
x0_moles = NULL;
if (k == 0)
return (OK);
x0_moles = (LDBLE *) free_check_null(x0_moles);
x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE));
if (x0_moles == NULL)
malloc_error();
if (x0_moles == NULL) malloc_error();
for (i = 0; i < k; i++)
{
x0_moles[i] = 0.0;

View File

@ -739,6 +739,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
error_string = sformatf( "Expected isotope name to"
" begin with an isotopic number.");
error_msg(error_string, PHRQ_io::OT_CONTINUE);
free_check_null(char_string);
continue;
}
temp_isotope.Set_isotope_name(token.c_str());
@ -768,6 +769,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
error_string = sformatf(
"Expected numeric value for isotope ratio.");
error_msg(error_string, CONTINUE);
free_check_null(char_string);
continue;
}
sscanf(token.c_str(), SCANFORMAT, &dummy);
@ -784,6 +786,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
error_string = sformatf(
"Expected numeric value for uncertainty in isotope ratio.");
error_msg(error_string, PHRQ_io::OT_CONTINUE);
free_check_null(char_string);
continue;
}
sscanf(token.c_str(), SCANFORMAT, &dummy);
@ -841,7 +844,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
{
next_char = char_string;
if (copy_token(token, &next_char) == LOWER)
{
free_check_null(char_string);
continue;
}
cxxISolutionComp temp_comp(this->phrq_io);
if (temp_comp.read(char_string, &temp_solution) == CParser::PARSER_ERROR)
{

View File

@ -175,6 +175,16 @@ step(LDBLE step_fraction)
Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save;
use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user()));
}
if (pp_assemblage_save != NULL)
{
delete pp_assemblage_save;
pp_assemblage_save = NULL;
}
if (ss_assemblage_save != NULL)
{
delete ss_assemblage_save;
ss_assemblage_save = NULL;
}
return (MASS_BALANCE);
}
/*
@ -191,6 +201,11 @@ step(LDBLE step_fraction)
delete pp_assemblage_save;
pp_assemblage_save = NULL;
}
if (ss_assemblage_save != NULL)
{
delete ss_assemblage_save;
ss_assemblage_save = NULL;
}
//
// Solution -1 has sum of solution/mix, exchange, surface, gas_phase
// reaction, kinetics

View File

@ -135,6 +135,10 @@ clean_up(void)
/* kinetics */
Rxn_kinetics_map.clear();
x0_moles = (LDBLE *) free_check_null(x0_moles);
m_temp = (LDBLE *) free_check_null(m_temp);
m_original = (LDBLE *) free_check_null(m_original);
rk_moles = (LDBLE *) free_check_null(rk_moles);
/* rates */
for (j = 0; j < count_rates; j++)