From: John Darrington Date: Fri, 21 Jan 2005 11:59:39 +0000 (+0000) Subject: Added linked-list.[ch] --- a general purpose linked list module. X-Git-Tag: v0.4.0~193 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7852df2743416201dc85fd672644799cdd1b7b5;p=pspp-builds.git Added linked-list.[ch] --- a general purpose linked list module. Fixed numerous memory leaks. Canonicalised the test output file names. --- diff --git a/src/ChangeLog b/src/ChangeLog index 956324af..0e90b935 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +Fri Jan 21 19:54:14 WST 2005 John Darrington + + * linked-list.[ch] Added + + * examine.q file-handle.[hq] font.h glob.c groff-font.c postscript.c + set.q: Yet more memory leaks + Tue Jan 18 23:12:40 WST 2005 John Darrington * t-test.q examine.q : More memory leaks fixed. diff --git a/src/Makefile.am b/src/Makefile.am index 01d651d4..1a6216d9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,8 +74,8 @@ file-type.c filename.c filename.h flip.c font.h format.c format.def \ format.h formats.c get.c getline.c getline.h glob.c glob.h \ groff-font.c group.c group.h group_proc.h \ hash.c hash.h histogram.c histogram.h \ -html.c htmlP.h include.c inpt-pgm.c lexer.c \ -lexer.h levene.c levene.h log.h loop.c magic.c magic.h main.c main.h \ +html.c htmlP.h include.c inpt-pgm.c lexer.c lexer.h levene.c levene.h \ +linked-list.c linked-list.h log.h loop.c magic.c magic.h main.c main.h \ matrix-data.c mis-val.c misc.c misc.h modify-vars.c \ moments.c moments.h numeric.c output.c output.h \ percentiles.c percentiles.h permissions.c \ diff --git a/src/examine.q b/src/examine.q index d49f9f16..4e28f239 100644 --- a/src/examine.q +++ b/src/examine.q @@ -218,6 +218,19 @@ cmd_examine(void) if ( dependent_vars ) free (dependent_vars); + { + struct factor *f = factors ; + while ( f ) + { + struct factor *ff = f; + + f = f->next; + free ( ff->fs ); + hsh_destroy ( ff->fstats ) ; + free ( ff ) ; + } + } + subc_list_double_destroy(&percentile_list); return CMD_SUCCESS; diff --git a/src/file-handle.h b/src/file-handle.h index 00a79109..ba0d7510 100644 --- a/src/file-handle.h +++ b/src/file-handle.h @@ -31,9 +31,15 @@ enum file_handle_mode MODE_BINARY /* Fixed-length records. */ }; + + +void fh_init(void); +void fh_done(void); + /* Parsing handles. */ struct file_handle *fh_parse (void); + /* Opening and closing handles. */ void **fh_open (struct file_handle *, const char *type, const char *mode); int fh_close (struct file_handle *, const char *type, const char *mode); diff --git a/src/file-handle.q b/src/file-handle.q index 9c3a81a3..cc499a99 100644 --- a/src/file-handle.q +++ b/src/file-handle.q @@ -30,6 +30,8 @@ #include "error.h" #include "magic.h" #include "var.h" +#include "linked-list.h" + /* (headers) */ /* File handle. */ @@ -215,6 +217,15 @@ create_file_handle (const char *handle_name, const char *filename) return handle; } +void +destroy_file_handle(struct file_handle *fh, void *aux UNUSED) +{ + free (fh->name); + free (fh->filename); + fn_free_identity (fh->identity); + free (fh); +} + static const char * mode_name (const char *mode) { @@ -304,6 +315,10 @@ fh_close (struct file_handle *h, const char *type, const char *mode) return h->open_cnt; } + +static struct linked_list *handle_list; + + /* Parses a file handle name, which may be a filename as a string or a file handle name as an identifier. Returns the file handle or NULL on failure. */ @@ -330,11 +345,13 @@ fh_parse (void) char *handle_name = xmalloc (strlen (filename) + 3); sprintf (handle_name, "\"%s\"", filename); handle = create_file_handle (handle_name, filename); + ll_push_front(handle_list, handle); free (handle_name); } lex_get (); + return handle; } @@ -386,6 +403,23 @@ handle_get_tab_width (const struct file_handle *handle) return handle->tab_width; } + +void +fh_init(void) +{ + handle_list = ll_create(destroy_file_handle,0); +} + +void +fh_done(void) +{ + assert(handle_list); + + ll_destroy(handle_list); + handle_list = 0; +} + + /* Local variables: mode: c diff --git a/src/font.h b/src/font.h index 67c276cd..c612c9f4 100644 --- a/src/font.h +++ b/src/font.h @@ -135,6 +135,7 @@ struct font_desc *groff_read_font (const char *fn); struct font_desc *groff_find_font (const char *dev, const char *name); int groff_read_DESC (const char *dev_name, struct groff_device_info * dev); void groff_init (void); +void groff_done (void); struct font_desc *default_font (void); diff --git a/src/glob.c b/src/glob.c index 457be8ac..159c4829 100644 --- a/src/glob.c +++ b/src/glob.c @@ -127,6 +127,7 @@ init_glob (int argc UNUSED, char **argv) #endif /* ENABLE_NLS */ fn_init (); + fh_init (); getl_initialize (); /* PORTME: If your system/OS has the nasty tendency to halt with a @@ -187,6 +188,8 @@ done_glob(void) free(logfn); done_settings(); ds_destroy (&tokstr); + + fh_done(); } static void diff --git a/src/groff-font.c b/src/groff-font.c index 331da33d..2787a793 100644 --- a/src/groff-font.c +++ b/src/groff-font.c @@ -48,12 +48,6 @@ static void add_kern (struct font_desc * font, int ch1, int ch2, int adjust); /* Typical whitespace characters for tokenizing. */ static const char whitespace[] = " \t\n\r\v"; -void -groff_init (void) -{ - space_index = font_char_name_to_index ("space"); -} - /* Some notes on the groff_font(8) manpage: DESC file format: A typical PostScript `res' would be 72000, with @@ -447,6 +441,20 @@ static struct } hash; +void +groff_init (void) +{ + space_index = font_char_name_to_index ("space"); +} + +void +groff_done (void) +{ + free (hash.tab) ; + pool_destroy(hash.ar); +} + + /* Searches for NAME in the global character code table, returns the index if found; otherwise inserts NAME and returns the new index. */ diff --git a/src/linked-list.c b/src/linked-list.c new file mode 100644 index 00000000..a98a3a18 --- /dev/null +++ b/src/linked-list.c @@ -0,0 +1,102 @@ +/* PSPP - computes sample statistics. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by John Darrington + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#include +#include +#include + +#include "alloc.h" +#include "linked-list.h" + +/* Iteration */ + +/* Return the first element in LL */ +void * +ll_first (const struct linked_list *ll, struct ll_iterator *li) +{ + assert(ll); + + li->p = ll->head; + + return ll->head->entry; +} + +/* Return the next element in LL iterated by LI */ +void * +ll_next (const struct linked_list *ll, struct ll_iterator *li) +{ + assert( ll ) ; + + li->p = li->p->next; + + if ( ! li->p ) + return 0; + + return li->p->entry; +} + + +/* Create a linked list. + Elements will be freed using F and AUX +*/ +struct linked_list * +ll_create( ll_free_func *f , void *aux) +{ + struct linked_list *ll = xmalloc ( sizeof(struct linked_list) ) ; + + ll->head = 0; + ll->free = f; + ll->aux = aux; + + return ll; +} + + +/* Destroy a linked list */ +void +ll_destroy(struct linked_list *ll) +{ + struct node *n = ll->head; + + while (n) + { + struct node *nn = n->next; + if ( ll->free ) + ll->free(n->entry, ll->aux); + free (n); + n = nn; + } + + free (ll); +} + + +/* Push a an element ENTRY onto the list LL */ +void +ll_push_front(struct linked_list *ll, void *entry) +{ + struct node *n ; + assert (ll); + + n = xmalloc (sizeof(struct node) ); + n->next = ll->head; + n->entry = entry; + ll->head = n; +} + diff --git a/src/linked-list.h b/src/linked-list.h new file mode 100644 index 00000000..56c8f411 --- /dev/null +++ b/src/linked-list.h @@ -0,0 +1,48 @@ +#ifndef LL_H +#define LL_H + + +struct node +{ + void *entry; + struct node *next; +}; + + + +typedef void ll_free_func (void *, void *aux); + +struct linked_list +{ + struct node *head; + ll_free_func *free; + void *aux; +}; + + +struct ll_iterator +{ + struct node *p; +}; + + +/* Iteration */ + +/* Return the first element in LL */ +void * ll_first (const struct linked_list *ll, struct ll_iterator *li); + +/* Return the next element in LL iterated by LI */ +void * ll_next (const struct linked_list *ll, struct ll_iterator *li); + +/* Create a linked list. + Elements will be freed using F and AUX +*/ +struct linked_list * ll_create( ll_free_func *F , void *aux); + +/* Destroy a linked list LL */ +void ll_destroy(struct linked_list *ll); + +/* Push a an element ENTRY onto the list LL */ +void ll_push_front(struct linked_list *ll, void *entry); + +#endif diff --git a/src/postscript.c b/src/postscript.c index 4a2fab0b..7b1f6e15 100644 --- a/src/postscript.c +++ b/src/postscript.c @@ -267,6 +267,7 @@ static unsigned hash_font_entry (const void *, void *param); static void free_font_entry (void *, void *foo); static struct font_entry *load_font (struct outp_driver *, const char *dit); static void init_fonts (void); +static void done_fonts (void); static void dump_lines (struct outp_driver *this); @@ -297,6 +298,8 @@ ps_open_global (struct outp_class *this UNUSED) static int ps_close_global (struct outp_class *this UNUSED) { + groff_done (); + done_fonts (); return 1; } @@ -2815,6 +2818,12 @@ init_fonts (void) NULL, NULL); } +static void +done_fonts (void) +{ + hsh_destroy (ps_fonts); +} + /* Loads the font having Groff name DIT into THIS driver instance. Specifically, adds it into the THIS driver's `loaded' hash table. */ @@ -2901,6 +2910,9 @@ struct outp_class postscript_class = ps_text_get_size, ps_text_metrics, ps_text_draw, + + NULL, + NULL }; /* EPSF driver class. FIXME: Probably doesn't work right. */ @@ -2942,6 +2954,9 @@ struct outp_class epsf_class = ps_text_get_size, ps_text_metrics, ps_text_draw, + + NULL, + NULL }; #endif /* NO_POSTSCRIPT */ diff --git a/src/set.q b/src/set.q index b6bcb23f..120606fb 100644 --- a/src/set.q +++ b/src/set.q @@ -1054,13 +1054,15 @@ set_viewport(int sig_num UNUSED) void done_settings(void) { - free(set_pager); - free(set_journal); - - free(cmd.s_endcmd); - free(cmd.s_prompt); - free(cmd.s_cprompt); - free(cmd.s_dprompt); + if ( rng ) + gsl_rng_free (rng); + free (set_pager); + free (set_journal); + + free (cmd.s_endcmd); + free (cmd.s_prompt); + free (cmd.s_cprompt); + free (cmd.s_dprompt); } diff --git a/tests/bugs/alpha-freq.sh b/tests/bugs/alpha-freq.sh index 102f98ba..fcd4eaca 100755 --- a/tests/bugs/alpha-freq.sh +++ b/tests/bugs/alpha-freq.sh @@ -4,6 +4,7 @@ # crash if given an alphanumeric variable TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/big-input-2.sh b/tests/bugs/big-input-2.sh index 83452262..cb89adf4 100755 --- a/tests/bugs/big-input-2.sh +++ b/tests/bugs/big-input-2.sh @@ -6,6 +6,7 @@ TEMPDIR=/tmp/pspp-tst-$$ TESTFILE=$TEMPDIR/`basename $0`.sps +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/big-input.sh b/tests/bugs/big-input.sh index d15cde4e..740147ea 100755 --- a/tests/bugs/big-input.sh +++ b/tests/bugs/big-input.sh @@ -5,6 +5,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/comment-at-eof.sh b/tests/bugs/comment-at-eof.sh index 0042b431..6f6ff259 100755 --- a/tests/bugs/comment-at-eof.sh +++ b/tests/bugs/comment-at-eof.sh @@ -4,6 +4,7 @@ # infinite loop. Thus, this test passes as long as it completes. TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/compute-fmt.sh b/tests/bugs/compute-fmt.sh index 90947510..b192f0c3 100755 --- a/tests/bugs/compute-fmt.sh +++ b/tests/bugs/compute-fmt.sh @@ -5,6 +5,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/computebug.sh b/tests/bugs/computebug.sh index 6340d521..01675aea 100755 --- a/tests/bugs/computebug.sh +++ b/tests/bugs/computebug.sh @@ -3,6 +3,7 @@ # This program tests for a bug in the `compute' command TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/crosstabs.sh b/tests/bugs/crosstabs.sh index a850750d..1635fe58 100755 --- a/tests/bugs/crosstabs.sh +++ b/tests/bugs/crosstabs.sh @@ -3,6 +3,7 @@ # This program tests for a bug which crashed pspp when doing a crosstabs TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/data-crash.sh b/tests/bugs/data-crash.sh index d005680d..b96c476e 100755 --- a/tests/bugs/data-crash.sh +++ b/tests/bugs/data-crash.sh @@ -4,6 +4,7 @@ # invalid input TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/double-frequency.sh b/tests/bugs/double-frequency.sh index e52b7185..9e90edc6 100755 --- a/tests/bugs/double-frequency.sh +++ b/tests/bugs/double-frequency.sh @@ -4,6 +4,7 @@ # Commands existed in a input file TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/examine-1sample.sh b/tests/bugs/examine-1sample.sh index 497ee892..b988d9e2 100755 --- a/tests/bugs/examine-1sample.sh +++ b/tests/bugs/examine-1sample.sh @@ -4,6 +4,7 @@ # would crash if a data file with only one case was presented TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/get.sh b/tests/bugs/get.sh index 3a57df03..d6c3f793 100755 --- a/tests/bugs/get.sh +++ b/tests/bugs/get.sh @@ -5,6 +5,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; diff --git a/tests/bugs/html-frequency.sh b/tests/bugs/html-frequency.sh index 474735fc..ba000ee2 100755 --- a/tests/bugs/html-frequency.sh +++ b/tests/bugs/html-frequency.sh @@ -6,6 +6,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd` diff --git a/tests/bugs/multipass.sh b/tests/bugs/multipass.sh index 00423547..bd4c2c39 100755 --- a/tests/bugs/multipass.sh +++ b/tests/bugs/multipass.sh @@ -4,6 +4,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; @@ -47,7 +48,7 @@ mkdir -p $TEMPDIR cd $TEMPDIR activity="create program" -cat > $TEMPDIR/rnd.sps < $TESTFILE < $TEMPDIR/rnd.sps < $TESTFILE < $TEMPDIR/rnd.sps < $TESTFILE < /dev/null +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE > /dev/null if [ $? -ne 1 ] ; then fail ; fi pass; diff --git a/tests/bugs/temporary.sh b/tests/bugs/temporary.sh index efb39ecc..3fbe1842 100755 --- a/tests/bugs/temporary.sh +++ b/tests/bugs/temporary.sh @@ -4,6 +4,7 @@ TEMPDIR=/tmp/pspp-tst-$$ +TESTFILE=$TEMPDIR/`basename $0`.sps here=`pwd`; @@ -47,7 +48,7 @@ mkdir -p $TEMPDIR cd $TEMPDIR activity="create program" -cat > $TEMPDIR/rnd.sps < $TESTFILE < $TEMPDIR/rnd.sps < $TESTFILE < /dev/null +$SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE > /dev/null if [ $? -ne 1 ] ; then fail ; fi pass;