From: John Darrington Date: Mon, 31 Jan 2005 01:54:57 +0000 (+0000) Subject: Fixed some more memory problems revealed by valgrind. X-Git-Tag: v0.4.0~186 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad5de775736ca47cc973cef22b5046f167385354;p=pspp-builds.git Fixed some more memory problems revealed by valgrind. --- diff --git a/src/ChangeLog b/src/ChangeLog index d94cc0d9..2b50e318 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ + +Mon Jan 31 09:52:51 WST 2005 John Darrington + + * examine.q factor_stats.c oneway.q output.c pfm-read.c: Fixed some + problems revealed by valgrind. + + Wed Jan 26 11:44:11 WST 2005 John Darrington * set.q: Affixed a fix to the previous fix such that we'll be OK now diff --git a/src/examine.q b/src/examine.q index 4e28f239..3454b66f 100644 --- a/src/examine.q +++ b/src/examine.q @@ -372,6 +372,8 @@ output_examine(void) } +/* Create a hash table of percentiles and their values from the list of + percentiles */ static struct hsh_table * list_to_ptile_hash(const subc_list_double *l) { @@ -391,6 +393,7 @@ list_to_ptile_hash(const subc_list_double *l) struct percentile *p = xmalloc (sizeof (struct percentile)); p->p = subc_list_double_at(l,i); + p->v = SYSMIS; hsh_insert(h, p); @@ -1527,12 +1530,14 @@ populate_descriptives(struct tab_table *tbl, int col, int row, assert(p); + tab_float (tbl, col + 2, row + 4, TAB_CENTER, p->v, 8, 2); } + tab_text (tbl, col, row + 5, diff --git a/src/factor_stats.c b/src/factor_stats.c index 8109a217..79c9b80c 100644 --- a/src/factor_stats.c +++ b/src/factor_stats.c @@ -44,6 +44,7 @@ metrics_precalc(struct metrics *m) m->min = DBL_MAX; m->max = -DBL_MAX; + m->histogram = 0; m->moments = moments1_create(MOMENT_KURTOSIS); @@ -141,6 +142,13 @@ metrics_postcalc(struct metrics *m) m->wvp = (struct weighted_value **) hsh_sort(m->ordered_data); m->n_data = hsh_count(m->ordered_data); + /* Trimmed mean calculation */ + if ( m->n_data <= 1 ) + { + m->trimmed_mean = m->mean; + return; + } + m->histogram = histogram_create(10, m->min, m->max); for ( i = 0 ; i < m->n_data ; ++i ) @@ -149,13 +157,6 @@ metrics_postcalc(struct metrics *m) gsl_histogram_accumulate(m->histogram, wv[i]->v.f, wv[i]->w); } - /* Trimmed mean calculation */ - if ( m->n_data <= 1 ) - { - m->trimmed_mean = m->mean; - return; - } - tc = m->n * 0.05 ; k1 = -1; k2 = -1; @@ -272,7 +273,8 @@ metrics_destroy(struct metrics *m) { hsh_destroy(m->ordered_data); hsh_destroy(m->ptile_hash); - gsl_histogram_free(m->histogram); + if ( m-> histogram ) + gsl_histogram_free(m->histogram); } void diff --git a/src/oneway.q b/src/oneway.q index 1d208204..7277b79a 100644 --- a/src/oneway.q +++ b/src/oneway.q @@ -140,7 +140,8 @@ cmd_oneway(void) multipass_procedure_with_splits (run_oneway, &cmd); - free_oneway(&cmd); + free (vars); + free_oneway (&cmd); return CMD_SUCCESS; } diff --git a/src/output.c b/src/output.c index f517ada0..f318cb86 100644 --- a/src/output.c +++ b/src/output.c @@ -455,6 +455,8 @@ outp_done (void) free(n); n = next; } + free (outp_title); + free (outp_subtitle); return 1; } diff --git a/src/pfm-read.c b/src/pfm-read.c index 5b64d25d..abc14edb 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -101,6 +101,8 @@ corrupt_msg (struct pfm_reader *r, const char *format, ...) return 0; } +static unsigned char * read_string (struct pfm_reader *r); + /* Closes a portable file after we're done with it. */ void pfm_close_reader (struct pfm_reader *r) @@ -108,6 +110,8 @@ pfm_close_reader (struct pfm_reader *r) if (r == NULL) return; + read_string (NULL); + if (r->fh != NULL) fh_close (r->fh, "portable file", "rs"); if (fclose (r->file) == EOF)