From: John Darrington Date: Mon, 27 Aug 2007 07:02:35 +0000 (+0000) Subject: Plugged some more memory leaks. X-Git-Tag: v0.6.0~290 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=614184c65fba060932911bbf2b8c6736d9e1452f;p=pspp-builds.git Plugged some more memory leaks. --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 155d4bf4..46abaa73 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -176,20 +176,7 @@ dict_clear (struct dictionary *d) while (d->var_cnt > 0 ) { - struct variable *v = d->var[d->var_cnt - 1]; - int dict_index = var_get_dict_index (v); - int case_index = var_get_case_index (v); - int val_cnt = var_get_value_cnt (v); - - var_clear_vardict (v); - var_destroy (v); - - d->var_cnt--; - - if (d->callbacks && d->callbacks->var_deleted ) - d->callbacks->var_deleted (d, - dict_index, case_index, val_cnt, - d->cb_data); + dict_delete_var (d, d->var[d->var_cnt - 1]); } free (d->var); @@ -516,6 +503,7 @@ dict_delete_var (struct dictionary *d, struct variable *v) var_clear_vardict (v); var_destroy (v); + if (d->callbacks && d->callbacks->var_deleted ) d->callbacks->var_deleted (d, dict_index, case_index, val_cnt, d->cb_data); } @@ -959,8 +947,16 @@ dict_set_split_vars (struct dictionary *d, assert (cnt == 0 || split != NULL); d->split_cnt = cnt; - d->split = cnt > 0 ? xnrealloc (d->split, cnt, sizeof *d->split) : NULL; - memcpy (d->split, split, cnt * sizeof *d->split); + if ( cnt > 0 ) + { + d->split = xnrealloc (d->split, cnt, sizeof *d->split) ; + memcpy (d->split, split, cnt * sizeof *d->split); + } + else + { + free (d->split); + d->split = NULL; + } if ( d->callbacks && d->callbacks->split_changed ) d->callbacks->split_changed (d, d->cb_data); diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 6527d271..8dd95ad5 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -939,6 +939,7 @@ read_long_var_name_map (struct sfm_reader *r, size_t size, size_t count, var_set_short_name (var, i, short_names[i]); free (short_names[i]); } + free (short_names); } close_variable_to_value_map (r, map); r->has_long_var_names = true; diff --git a/src/data/variable.c b/src/data/variable.c index dcd91800..b3b34be0 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -173,6 +173,7 @@ var_destroy (struct variable *v) { assert (!var_has_vardict (v)); cat_stored_values_destroy (v->obs_vals); + var_clear_short_names (v); var_clear_aux (v); val_labs_destroy (v->val_labs); var_clear_label (v); @@ -840,7 +841,6 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name) { size_t old_cnt = var->short_name_cnt; size_t i; - var->short_name_cnt = MAX (idx * 2, 1); var->short_names = xnrealloc (var->short_names, var->short_name_cnt, sizeof *var->short_names); @@ -859,9 +859,10 @@ void var_clear_short_names (struct variable *v) { size_t i; - + for (i = 0; i < v->short_name_cnt; i++) free (v->short_names[i]); + free (v->short_names); v->short_names = NULL; v->short_name_cnt = 0; }