From: John Darrington Date: Tue, 18 Jan 2005 11:31:45 +0000 (+0000) Subject: Fixed numerous memory leaks. Changed many of the test cases to use a canonical X-Git-Tag: sav-api~2432 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a19e7749cdb8713316fde220f2fc9a5ad5dc79ed;p=pspp Fixed numerous memory leaks. Changed many of the test cases to use a canonical format for the temporary test file names. --- diff --git a/src/ChangeLog b/src/ChangeLog index b4e9b12c4a..a0a45cb0ab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Tue Jan 18 19:26:59 WST 2005 John Darrington + + * examine.q factor_stats.[ch] get.c pfm-read.c: Plugged numerous + memory leaks. + Mon Jan 10 14:43:45 WST 2005 John Darrington * ascii.c cartesian.c casefile.c chart.h devind.c diff --git a/src/examine.q b/src/examine.q index 469b413c74..7d5c2b2b9d 100644 --- a/src/examine.q +++ b/src/examine.q @@ -132,7 +132,7 @@ void box_plot_group(const struct factor *fctr, void box_plot_variables(const struct factor *fctr, - struct variable **vars, int n_vars, + const struct variable **vars, int n_vars, const struct variable *id ); @@ -211,7 +211,10 @@ cmd_examine(void) multipass_procedure_with_splits (run_examine, &cmd); if ( totals ) - free(totals); + free( totals ); + + if ( dependent_vars ) + free (dependent_vars); subc_list_double_destroy(&percentile_list); @@ -485,6 +488,7 @@ xmn_custom_variables(struct cmd_examine *cmd ) assert(n_dependent_vars); totals = xmalloc( sizeof(struct metrics) * n_dependent_vars); + memset ( totals, 0, sizeof(struct metrics) * n_dependent_vars); if ( lex_match(T_BY)) { @@ -786,8 +790,13 @@ run_examine(const struct casefile *cf, void *cmd_ ) output_examine(); - for ( v = 0 ; v < n_dependent_vars ; ++v ) - hsh_destroy(totals[v].ordered_data); + + if ( totals ) + { + int i; + for ( i = 0 ; i < n_dependent_vars ; ++i ) + metrics_destroy(&totals[i]); + } } @@ -1623,7 +1632,7 @@ populate_descriptives(struct tab_table *tbl, int col, int row, void box_plot_variables(const struct factor *fctr, - struct variable **vars, int n_vars, + const struct variable **vars, int n_vars, const struct variable *id) { @@ -1687,7 +1696,7 @@ void box_plot_group(const struct factor *fctr, const struct variable **vars, int n_vars, - const struct variable *id) + const struct variable *id UNUSED) { int i; diff --git a/src/factor_stats.c b/src/factor_stats.c index 7c4cce000f..8109a2171f 100644 --- a/src/factor_stats.c +++ b/src/factor_stats.c @@ -124,7 +124,6 @@ metrics_postcalc(struct metrics *m) int i; int j = 1; - moments1_calculate (m->moments, &m->n, &m->mean, &m->var, &m->skewness, &m->kurtosis); @@ -207,6 +206,7 @@ metrics_postcalc(struct metrics *m) m->trimmed_mean += (m->wvp[k1 + 1]->cc - tc) * m->wvp[k1 + 1]->v.f ; m->trimmed_mean /= 0.9 * m->n ; + } @@ -225,7 +225,12 @@ weighted_value_create(void) void weighted_value_free(struct weighted_value *wv) { - struct case_node *cn = wv->case_nos; + struct case_node *cn ; + + if ( !wv ) + return ; + + cn = wv->case_nos; while(cn) { @@ -255,16 +260,28 @@ create_factor_statistics (int n, union value *id0, union value *id1) f->id[0] = *id0; f->id[1] = *id1; f->m = xmalloc( sizeof ( struct metrics ) * n ) ; + memset (f->m, 0, sizeof(struct metrics) * n); + f->n_var = n; return f; } +void +metrics_destroy(struct metrics *m) +{ + hsh_destroy(m->ordered_data); + hsh_destroy(m->ptile_hash); + gsl_histogram_free(m->histogram); +} + void factor_statistics_free(struct factor_statistics *f) { - hsh_destroy(f->m->ordered_data); - gsl_histogram_free(f->m->histogram); + + int i; + for ( i = 0 ; i < f->n_var; ++i ) + metrics_destroy(&f->m[i]); free(f->m) ; free(f); } diff --git a/src/factor_stats.h b/src/factor_stats.h index b05d7423e0..259694e8fc 100644 --- a/src/factor_stats.h +++ b/src/factor_stats.h @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "hash.h" #include "val.h" +#include #include #include "subclist.h" #include "percentiles.h" @@ -85,6 +86,8 @@ struct metrics }; +struct metrics * metrics_create(void); + void metrics_precalc(struct metrics *m); void metrics_calc(struct metrics *m, const union value *f, double weight, @@ -92,6 +95,9 @@ void metrics_calc(struct metrics *m, const union value *f, double weight, void metrics_postcalc(struct metrics *m); +void metrics_destroy(struct metrics *m); + + /* Linked list of case nos */ struct case_node @@ -133,6 +139,8 @@ struct factor_statistics { /* The an array stats for this factor, one for each dependent var */ struct metrics *m; + /* The number of dependent variables */ + int n_var; }; diff --git a/src/get.c b/src/get.c index 8f98dea460..7fcb1f250a 100644 --- a/src/get.c +++ b/src/get.c @@ -242,6 +242,7 @@ cmd_save (void) { procedure (save_write_case_func, t); save_trns_free (&t->h); + free(t); return CMD_SUCCESS; } else @@ -549,12 +550,14 @@ cmd_export (void) procedure (export_write_case_func, proc); export_proc_free (proc); + free (proc); return CMD_SUCCESS; error: dict_destroy (dict); export_proc_free (proc); + free (proc); return CMD_FAILURE; } @@ -1623,20 +1626,21 @@ finish_case_map (struct dictionary *d) for (i = 0; i < var_cnt; i++) { struct variable *v = dict_get_var (d, i); - int src_fv = *(int *) var_detach_aux (v); + int *src_fv = (int *) var_detach_aux (v); size_t idx; - if (v->fv != src_fv) + if (v->fv != *src_fv) identity_map = 0; for (idx = 0; idx < v->nv; idx++) { - int src_idx = src_fv + idx; + int src_idx = *src_fv + idx; int dst_idx = v->fv + idx; assert (map->map[dst_idx] == -1); map->map[dst_idx] = src_idx; } + free (src_fv); } if (identity_map) diff --git a/src/pfm-read.c b/src/pfm-read.c index d551b1c17d..5b64d25d27 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -114,6 +114,7 @@ pfm_close_reader (struct pfm_reader *r) msg (ME, _("%s: Closing portable file: %s."), handle_get_filename (r->fh), strerror (errno)); free (r->trans); + free (r->widths); free (r); } diff --git a/tests/ChangeLog b/tests/ChangeLog index 191e647033..63b1959aed 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +Tue Jan 18 19:25:24 WST 2005 John Darrington + + * Canonicalised (some of) the tests' temp file names to make it + easier to recognise valgrind ouput. + Sun Jan 9 16:39:08 WST 2005 John Darrington * bugs/big-input-2.sh Made the test a bit faster diff --git a/tests/bugs/big-input-2.sh b/tests/bugs/big-input-2.sh index bd53c20667..834522628e 100755 --- a/tests/bugs/big-input-2.sh +++ b/tests/bugs/big-input-2.sh @@ -5,6 +5,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; @@ -65,7 +66,7 @@ if [ $? -ne 0 ] ; then no_result ; fi printf "\n"; activity="create program" -cat > $TEMPDIR/large.sps < $TESTFILE < /dev/null +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE > /dev/null if [ $? -ne 0 ] ; then fail ; fi activity="appending to data" @@ -89,7 +90,7 @@ done ) | head -50000 >> $TEMPDIR/large.dat if [ $? -ne 0 ] ; then no_result ; fi activity="run program" -$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/large.sps > /dev/null +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE > /dev/null if [ $? -ne 0 ] ; then fail ; fi pass; diff --git a/tests/command/aggregate.sh b/tests/command/aggregate.sh index 916587dc0c..c03852ecd7 100755 --- a/tests/command/aggregate.sh +++ b/tests/command/aggregate.sh @@ -3,6 +3,8 @@ # This program tests the aggregate procedure TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps + here=`pwd`; @@ -46,7 +48,7 @@ mkdir -p $TEMPDIR cd $TEMPDIR activity="program create" -cat > $TEMPDIR/test.sps << EOF +cat > $TESTFILE << EOF data list notable /x y 1-2. begin data. @@ -69,7 +71,7 @@ EOF if [ $? -ne 0 ] ; then no_result ; fi activity="run program" -$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/test.sps +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE if [ $? -ne 0 ] ; then no_result ; fi activity="test result" diff --git a/tests/command/autorecod.sh b/tests/command/autorecod.sh index 01c90904a2..2f5acea07d 100755 --- a/tests/command/autorecod.sh +++ b/tests/command/autorecod.sh @@ -3,6 +3,8 @@ # This program tests the autorecode command TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps + here=`pwd`; @@ -46,7 +48,7 @@ mkdir -p $TEMPDIR cd $TEMPDIR activity="create program" -cat > $TEMPDIR/prog.sps < $TESTFILE < $TEMPDIR/prog.sps << EOF_foobar +cat > $TESTFILE << EOF_foobar title 'Test BEGIN DATA ... END DATA'. data list /A B 1-2. @@ -73,7 +74,7 @@ if [ $? -ne 0 ] ; then no_result ; fi activity="run program" -$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE if [ $? -ne 0 ] ; then no_result ; fi activity="compare data" diff --git a/tests/command/bignum.sh b/tests/command/bignum.sh index a6465426e4..24d0dd3f2c 100755 --- a/tests/command/bignum.sh +++ b/tests/command/bignum.sh @@ -3,6 +3,7 @@ # This program tests the use of big numbers TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; @@ -114,7 +115,7 @@ if [ $? -ne 0 ] ; then no_result ; fi activity="create program" -cat > $TEMPDIR/prog.stat < $TESTFILE < $TEMPDIR/count.stat < $TESTFILE < $TEMPDIR/data-list.stat << EOF +cat > $TESTFILE << EOF data list list ('|','X') /A B C D. begin data. 1|23X45|2.03 @@ -99,7 +100,7 @@ if [ $? -ne 0 ] ; then no_result ; fi activity="run program" -$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii --testing-mode $TEMPDIR/data-list.stat # > $TEMPDIR/errs +$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii --testing-mode $TESTFILE if [ $? -ne 0 ] ; then fail ; fi activity="compare output" diff --git a/tests/command/erase.sh b/tests/command/erase.sh index ba65d474e6..760ac7d881 100755 --- a/tests/command/erase.sh +++ b/tests/command/erase.sh @@ -3,6 +3,7 @@ # This program tests the ERASE command. TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; @@ -56,7 +57,7 @@ if [ ! -f $TEMPDIR/foobar ] ; then no_result ; fi activity="create program 1" -cat > $TEMPDIR/foo.sps < $TESTFILE < /dev/null +$SUPERVISOR $here/../src/pspp $TESTFILE > /dev/null if [ $? -eq 0 ] ; then fail ; fi activity="create program 2" -cat > $TEMPDIR/foo.sps < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/prog.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/out.stat < $TESTFILE < $TEMPDIR/weight.stat < $TESTFILE << EOF data list file='$top_srcdir/tests/weighting.data'/AVAR 1-5 BVAR 6-10. weight by BVAR. @@ -58,7 +59,7 @@ if [ $? -ne 0 ] ; then no_result ; fi activity="run program" -$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TEMPDIR/weight.stat +$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TESTFILE if [ $? -ne 0 ] ; then no_result ; fi activity="compare results"