# HG changeset patch # User jwe # Date 754882219 0 # Node ID d66cc97f77a97d510c87cc087f12a66d661286a8 # Parent 5b2f4a58254bc2678d48ae8a04346ec9206bc862 [project @ 1993-12-03 01:30:19 by jwe] diff -r 5b2f4a58254b -r d66cc97f77a9 src/help.cc --- a/src/help.cc Tue Nov 30 23:48:47 1993 +0000 +++ b/src/help.cc Fri Dec 03 01:30:19 1993 +0000 @@ -245,7 +245,7 @@ ptr++; } - name_list[count] = (char *) NULL; + name_list[i] = (char *) NULL; return name_list; } diff -r 5b2f4a58254b -r d66cc97f77a9 src/input.cc --- a/src/input.cc Tue Nov 30 23:48:47 1993 +0000 +++ b/src/input.cc Fri Dec 03 01:30:19 1993 +0000 @@ -303,7 +303,12 @@ len = strlen (text); if (name_list != (char **) NULL) - delete [] name_list; + { + char **ptr = name_list; + while (ptr && *ptr) + delete [] *ptr++; + delete [] name_list; + } name_list = make_name_list (); } @@ -313,7 +318,11 @@ { list_index++; if (strncmp (name, text, len) == 0) - return name; + { + char *buf = xmalloc (1 + strlen (name)); + strcpy (buf, name); + return buf; + } } return (char *) NULL; diff -r 5b2f4a58254b -r d66cc97f77a9 src/symtab.cc --- a/src/symtab.cc Tue Nov 30 23:48:47 1993 +0000 +++ b/src/symtab.cc Fri Dec 03 01:30:19 1993 +0000 @@ -980,8 +980,7 @@ { if (save (os, *ptr, mark_as_global)) status++; - - ptr++; + delete [] *ptr++; } delete [] names; } diff -r 5b2f4a58254b -r d66cc97f77a9 src/utils.cc --- a/src/utils.cc Tue Nov 30 23:48:47 1993 +0000 +++ b/src/utils.cc Fri Dec 03 01:30:19 1993 +0000 @@ -362,17 +362,11 @@ } } -// Why do I have to do this? - char **foo = path; while (foo && *foo) - { - delete [] *foo; - *foo = (char *) NULL; - foo++; - } - + delete [] *foo++; delete [] path; + path = new char * [nelem+1]; path[nelem] = (char *) NULL; @@ -1313,11 +1307,17 @@ if (i == num_max - 1) { +// Reallocate the array. Only copy pointers, not the strings they +// point to, then only delete the original array of pointers, and not +// the strings they point to. + num_max += 256; char **tmp = new char * [num_max]; for (int j = 0; j < i; j++) tmp[j] = retval[j]; + delete [] retval; + retval = tmp; } } @@ -1350,11 +1350,17 @@ if (i + tmp_num >= num_max - 1) { +// Reallocate the array. Only copy pointers, not the strings they +// point to, then only delete the original array of pointers, and not +// the strings they point to. + num_max += 1024; char **tmp = new char * [num_max]; for (int j = 0; j < i; j++) tmp[j] = retval[j]; + delete [] retval; + retval = tmp; } diff -r 5b2f4a58254b -r d66cc97f77a9 src/variables.cc --- a/src/variables.cc Tue Nov 30 23:48:47 1993 +0000 +++ b/src/variables.cc Fri Dec 03 01:30:19 1993 +0000 @@ -694,6 +694,9 @@ char **lcl = (char **) NULL; char **mfl = (char **) NULL; +// Each of these functions returns a new vector of pointers to new +// strings. + key = names (keyword_help (), key_len); glb = global_sym_tab->list (glb_len); top = top_level_sym_tab->list (top_len); @@ -705,22 +708,26 @@ char **list = new char * [total_len+1]; +// Put all the symbols in one big list. Only copy pointers, not the +// strings they point to, then only delete the original array of +// pointers, and not the strings they point to. + int j = 0; int i = 0; for (i = 0; i < key_len; i++) - list[j++] = strsave (key[i]); + list[j++] = key[i]; for (i = 0; i < glb_len; i++) - list[j++] = strsave (glb[i]); + list[j++] = glb[i]; for (i = 0; i < top_len; i++) - list[j++] = strsave (top[i]); + list[j++] = top[i]; for (i = 0; i < lcl_len; i++) - list[j++] = strsave (lcl[i]); + list[j++] = lcl[i]; for (i = 0; i < mfl_len; i++) - list[j++] = strsave (mfl[i]); + list[j++] = mfl[i]; list[j] = (char *) NULL;