From eeb3352d718b0cd85afab3f7a7466fcac7791c1c Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 19 Nov 2004 06:06:21 +0000 Subject: [PATCH] Plugged some memory leaks. --- src/ChangeLog | 7 +++++++ src/ascii.c | 20 +++++++++++++++++--- src/error.c | 4 ++++ src/frequencies.q | 2 ++ src/getline.c | 2 ++ src/glob.c | 9 +++++++++ src/glob.h | 1 + src/lexer.c | 7 +++++++ src/lexer.h | 1 + src/output.c | 8 ++++++++ src/output.h | 3 --- src/q2c.c | 5 ++++- src/settings.h | 1 + 13 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 88dd8b6e..dbf1f89c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +John Darrington + + * settings.h set.c glob.[ch] frequencies.q q2c.c error.c lexer.[ch] + output.[ch] getline.c + + Plugged some memory leaks + Mon Nov 15 23:47:40 2004 Ben Pfaff Adopt GSL random number generators, paving the way for providing diff --git a/src/ascii.c b/src/ascii.c index 6fa1573b..4a30663f 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -187,16 +187,26 @@ struct ascii_driver_ext static int postopen (struct file_ext *); static int preclose (struct file_ext *); +static struct outp_option_info *option_info; + static int ascii_open_global (struct outp_class *this UNUSED) { + option_info = xmalloc ( sizeof (struct outp_option_info ) ) ; + option_info->initial = 0; + option_info->options = 0; return 1; } +static unsigned char *s=0; static int ascii_close_global (struct outp_class *this UNUSED) { + free(option_info->initial); + free(option_info->options); + free(option_info); + free(s); return 1; } @@ -456,7 +466,6 @@ static struct outp_option option_tab[] = {"squeeze", boolean_arg, 2}, {"", 0, 0}, }; -static struct outp_option_info option_info; static void ascii_option (struct outp_driver *this, const char *key, @@ -484,7 +493,7 @@ ascii_option (struct outp_driver *this, const char *key, return; } - cat = outp_match_keyword (key, option_tab, &option_info, &subcat); + cat = outp_match_keyword (key, option_tab, option_info, &subcat); switch (cat) { case 0: @@ -1518,10 +1527,10 @@ output_lines (struct outp_driver *this, int first, int count) } } + static int ascii_close_page (struct outp_driver *this) { - static unsigned char *s; static int s_len; struct ascii_driver_ext *x = this->ext; @@ -1610,8 +1619,13 @@ ascii_close_page (struct outp_driver *this) memcpy (cp, ls_c_str (&x->ops[OPS_FORMFEED]), ff_len); if ( x->paginate ) output_string (this, s, &s[total_len]); + if (line_p != line_buf && !commit_line_buf (this)) + { + free(s); + s=0; return 0; + } this->page_open = 0; return 1; diff --git a/src/error.c b/src/error.c index 2e012b4b..e062f5cc 100644 --- a/src/error.c +++ b/src/error.c @@ -223,9 +223,13 @@ err_hcf (int success) { terminating = 1; + lex_done(); getl_uninitialize (); + free(file_loc); outp_done (); + done_glob(); + exit (success ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/src/frequencies.q b/src/frequencies.q index 8393819c..649f09cd 100644 --- a/src/frequencies.q +++ b/src/frequencies.q @@ -319,6 +319,8 @@ internal_cmd_frequencies (void) /* Do it! */ procedure_with_splits (precalc, calc, postcalc, NULL); + free_frequencies(&cmd); + return CMD_SUCCESS; } diff --git a/src/getline.c b/src/getline.c index a5b0148e..21fdc524 100644 --- a/src/getline.c +++ b/src/getline.c @@ -85,6 +85,8 @@ getl_uninitialize (void) if (history_file) write_history (history_file); #endif + ds_destroy (&getl_buf); + ds_destroy (&getl_include_path); } /* Returns a string that represents the directory that the syntax file diff --git a/src/glob.c b/src/glob.c index 9b4f93c4..457be8ac 100644 --- a/src/glob.c +++ b/src/glob.c @@ -180,6 +180,15 @@ init_glob (int argc UNUSED, char **argv) get_date (); } +void +done_glob(void) +{ + dict_destroy(default_dict); + free(logfn); + done_settings(); + ds_destroy (&tokstr); +} + static void get_date (void) { diff --git a/src/glob.h b/src/glob.h index 254b3cdd..91b70277 100644 --- a/src/glob.h +++ b/src/glob.h @@ -21,5 +21,6 @@ #define INCLUDED_GLOB_H 1 void init_glob (int argc UNUSED, char **argv); +void done_glob (void); #endif /* glob.h */ diff --git a/src/lexer.c b/src/lexer.c index e72f7f1b..e573bbb7 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -99,6 +99,13 @@ lex_init (void) if (!lex_get_line ()) unexpected_eof (); } + +void +lex_done (void) +{ + ds_destroy(&put_tokstr); +} + /* Common functions. */ diff --git a/src/lexer.h b/src/lexer.h index 1561d793..00281281 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -78,6 +78,7 @@ extern struct string tokstr; /* Initialization. */ void lex_init (void); +void lex_done (void); /* Common functions. */ void lex_get (void); diff --git a/src/output.c b/src/output.c index e33172e2..f517ada0 100644 --- a/src/output.c +++ b/src/output.c @@ -442,12 +442,20 @@ destroy_list (struct outp_driver ** dl) int outp_done (void) { + struct outp_driver_class_list *n = outp_class_list ; #if GLOBAL_DEBUGGING if (iterating_driver_list) reentrancy (); #endif destroy_list (&outp_driver_list); + while (n) + { + struct outp_driver_class_list *next = n->next; + free(n); + n = next; + } + return 1; } diff --git a/src/output.h b/src/output.h index bcd09328..4b31f050 100644 --- a/src/output.h +++ b/src/output.h @@ -228,9 +228,6 @@ struct outp_driver_class_list struct outp_driver_class_list *next; }; -/* List of known output driver classes. */ -extern struct outp_driver_class_list *outp_class_list; - /* List of configured output drivers. */ extern struct outp_driver *outp_driver_list; diff --git a/src/q2c.c b/src/q2c.c index 0ffc79f0..5d188bbc 100644 --- a/src/q2c.c +++ b/src/q2c.c @@ -2062,7 +2062,10 @@ dump_free (int persistent) dump (0, "free (p->s_%s);", st_lower (sbc->name)); break; case SBC_DBL_LIST: - dump (0, "subc_list_double_destroy(p->dl_%s);", st_lower (sbc->name)); + dump (0, "int i;"); + dump (1, "for(i = 0; i < MAXLISTS ; ++i)"); + dump (0, "subc_list_double_destroy(&p->dl_%s[i]);", st_lower (sbc->name)); + outdent(); break; default: break; diff --git a/src/settings.h b/src/settings.h index 4c196b7e..74e81b5e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -139,6 +139,7 @@ int get_viewlength(void); int get_viewwidth(void); void init_settings(void) ; +void done_settings(void) ; /* Whether pspp can erase and overwrite files */ int safer_mode(void); -- 2.30.2