[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] 1.1.6 mem leaks revisited
From: |
Steven Kneizys |
Subject: |
[Nano-devel] 1.1.6 mem leaks revisited |
Date: |
Sun, 24 Feb 2002 13:24:36 -0800 (PST) |
Greetings,
I have given up on trying to fix all the leaks at once. I noticed that
trying to fix the minor browsing path name leak work sometimes, not
others, resulting in 'multiple frees' errors which would result in
segfaults for some folks. I have deleted most of that code for now.
However, the multibuffer leaks fix seem to be stable. I downloaded
everything from CVS that has been changed in the last week and then did
a diff on it versus my tree, and the result is the patch below. The
leaked bytes amount to a few hundred or less, much better than the
1.4Meg one can get in a few mins otherwise ;-)
thanks,
Steve...
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
diff -u -b nano-1.1.6/files.c nano-1.1.6-cvs.debug/files.c
--- nano-1.1.6/files.c Sun Feb 24 14:16:15 2002
+++ nano-1.1.6-cvs.debug/files.c Sun Feb 24 15:36:33 2002
@@ -366,7 +366,17 @@
currshortcut = insertfile_list;
#endif
+#ifndef DISABLE_OPERATINGDIR
+ if ((operating_dir) && (strcmp(operating_dir,"."))){
+ i = statusq(1, insertfile_list, "", _("File to insert [from %s] "),
+ operating_dir);
+ } else {
+#endif
i = statusq(1, insertfile_list, "", _("File to insert [from ./] "));
+#ifndef DISABLE_OPERATINGDIR
+ }
+#endif
+
if (i != -1) {
#ifdef DEBUG
@@ -412,7 +422,6 @@
/* update the current entry in the open_files structure */
add_open_file(1);
- free_filestruct(fileage);
new_file();
UNSET(MODIFIED);
}
@@ -508,6 +517,7 @@
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
+ open_files->file = NULL;
}
else if (!update) {
@@ -526,6 +536,7 @@
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
+ open_files->file = NULL;
}
/* save current filename */
@@ -555,8 +566,7 @@
if (!(ISSET(VIEW_MODE) && !update)) {
/* save current filestruct and restore full file position
afterward */
- open_files->file = nmalloc(sizeof(filestruct));
- open_files->file = copy_filestruct(fileage);
+ open_files->file = fileage;
do_gotopos(open_files->lineno, open_files->file_current_x,
open_files->file_current_y, open_files->file_placewewant);
}
@@ -598,7 +608,7 @@
/* set up the filename, the file buffer, the total number of lines in
the file, and the total file size */
filename = mallocstrcpy(filename, open_files->data);
- fileage = copy_filestruct(open_files->file);
+ fileage = open_files->file;
current = fileage;
totlines = open_files->file_totlines;
totsize = open_files->file_totsize;
@@ -679,8 +689,12 @@
}
+/* free_filestruct(fileage);/* delete this before reloading */
load_open_file();
+ statusbar(_("Switched to %s"),
+ ((open_files->data[0] == '\0') ? "New Buffer" : open_files->data ));
+
#ifdef DEBUG
dump_buffer(current);
#endif
@@ -740,8 +754,11 @@
}
}
load_open_file();
+ statusbar(_("Switched to %s"),
+ ((open_files->data[0] == '\0') ? "New Buffer" : open_files->data ));
+
#ifdef DEBUG
dump_buffer(current);
#endif
@@ -1069,10 +1087,10 @@
*/
int check_operating_dir(char *currpath, int allow_tabcomp)
{
- /* this is static so that we only need to get it the first time this
- function is called; also, a relative operating directory path will
+ /* The char *full_operating_dir is global for mem cleanup, and
+ therefore we only need to get it the first time this function
+ is called; also, a relative operating directory path will
only be handled properly if this is done */
- static char *full_operating_dir = NULL;
char *fullpath, *whereami1, *whereami2 = NULL;
@@ -1151,11 +1169,11 @@
int write_file(char *name, int tmp, int append, int nonamechange)
{
long size, lineswritten = 0;
- static char *buf = NULL;
+ char *buf = NULL;
filestruct *fileptr;
int fd, mask = 0, realexists, anyexists;
struct stat st, lst;
- static char *realname = NULL;
+ char *realname = NULL;
if (!strcmp(name, "")) {
statusbar(_("Cancelled"));
@@ -2088,7 +2106,7 @@
{
int i;
- for (i = 0; i < len - 1; i++)
+ for (i = 0; i < len; i++)
free(array[i]);
free(array);
}
@@ -2127,7 +2145,10 @@
if (tmp != foo)
*tmp = 0;
else
+ { /* SPK may need to make a 'default' path here */
+ if (*tmp != '/') *(tmp) = '.';
*(tmp+1) = 0;
+ }
return;
}
@@ -2321,6 +2342,17 @@
}
#endif
+ /* SPK for '.' path, get the current path via getcwd */
+ if (!strcmp(path, "./..")) {
+ free(path);
+ path = getcwd(NULL, 0);
+ striponedir(path);
+ align(&path);
+ free_charptrarray(filelist, numents);
+ free(foo);
+ return do_browser(path);
+ }
+
st = filestat(path);
if (S_ISDIR(st.st_mode)) {
if ((test_dir = opendir(path)) == NULL) {
@@ -2341,6 +2373,8 @@
}
/* Start over again with the new path value */
+ free_charptrarray(filelist, numents);
+ free(foo);
return do_browser(path);
} else {
retval = path;
@@ -2375,7 +2409,7 @@
char *saveanswer = NULL;
saveanswer = mallocstrcpy(saveanswer, answer);
- answer = realloc(answer, strlen(path) + strlen(saveanswer) + 2);
+ answer = nrealloc(answer, strlen(path) + strlen(saveanswer) +
2);
sprintf(answer, "%s/%s", path, saveanswer);
free(saveanswer);
}
diff -u -b nano-1.1.6/global.c nano-1.1.6-cvs.debug/global.c
--- nano-1.1.6/global.c Sun Feb 24 14:16:25 2002
+++ nano-1.1.6-cvs.debug/global.c Sun Feb 24 15:32:01 2002
@@ -77,8 +77,8 @@
int mark_beginx; /* X value in the string to start */
#ifndef DISABLE_OPERATINGDIR
-char *operating_dir = NULL; /* Operating directory, which we can't go
- higher than */
+char *operating_dir = NULL; /* Operating directory, which we can't */
+char *full_operating_dir = NULL;/* go higher than */
#endif
#ifndef DISABLE_SPELLER
@@ -655,4 +655,125 @@
#endif
toggle_init();
+}
+
+/* delete the structure */
+int free_shortcutage(shortcut **shortcutage)
+{
+ shortcut *s,*ps;
+
+ s = *shortcutage;
+ if (s == NULL) {
+ return;
+ } else {
+ s = *shortcutage;
+ do {
+ ps = s;
+ s = s->next;
+ free(ps);
+ } while (s->next != NULL);
+ free(s);
+ *shortcutage = NULL;
+ }
+}
+
+#ifndef NANO_SMALL
+/* clear the toggles */
+void free_toggles(void)
+{
+ toggle *u,*lu;
+
+ if (toggles == NULL) {
+ return;
+ } else {
+ lu = NULL;
+ for (u = toggles; u->next != NULL; u = u->next) {
+ if (lu != NULL) free(lu);
+ lu = u;
+ }
+ if (lu != NULL) free(lu);
+ if (u != NULL) free(u);
+ }
+}
+#endif
+
+/* added by SPK for memory cleanup, gracefully return our malloc()s */
+int thanks_for_the_memories(void)
+{
+#ifdef ENABLE_MULTIBUFFER
+ filestruct * current_open_file;
+#endif
+
+ zmcomment("starting the cleanup now . . .");
+#ifdef ENABLE_MULTIBUFFER
+ if (operating_dir != NULL)
+ free(operating_dir);
+ if (full_operating_dir != NULL)
+ free(full_operating_dir);
+#endif
+ if (last_search != NULL)
+ free(last_search);
+ if (last_replace != NULL)
+ free(last_replace);
+ if (hblank != NULL)
+ free(hblank);
+#ifndef DISABLE_SPELLER
+ if (alt_speller != NULL)
+ free(alt_speller);
+#endif
+ if (help_text != NULL)
+ free(help_text);
+ if (filename != NULL)
+ free(filename);
+ if (answer != NULL)
+ free(answer);
+ if (cutbuffer != NULL)
+ free_filestruct(cutbuffer);
+
+ free_shortcutage(&main_list);
+ free_shortcutage(&whereis_list);
+ free_shortcutage(&replace_list);
+ free_shortcutage(&replace_list_2);
+ free_shortcutage(&help_list);
+ free_shortcutage(&writefile_list);
+ free_shortcutage(&insertfile_list);
+ free_shortcutage(&spell_list);
+#ifndef DISABLE_BROWSER
+ free_shortcutage(&browser_list);
+#endif
+ free_shortcutage(&gotodir_list);
+ free_shortcutage(&goto_list);
+
+#ifndef NANO_SMALL
+ free_toggles();
+#endif
+
+#ifdef ENABLE_MULTIBUFFER
+/* Cleanup of Multibuffers . . .
+ Do not cleanup the current one, that is fileage . . . do the
+ rest of them though! (should be none if all went well) */
+ current_open_file = open_files;
+ if (open_files != NULL){
+ while (open_files->prev != NULL)
+ open_files = open_files->prev;
+ while (open_files->next != NULL) {
+ /* cleanup of a multi buf . . . */
+ if (open_files != current_open_file)
+ free_filestruct(open_files->file);
+ open_files = open_files->next;
+ free_filestruct(open_files->prev);
+ }
+ /* cleanup of last multi buf . . . */
+ if (open_files != current_open_file)
+ free_filestruct(open_files->file);
+ free_filestruct(open_files);
+ }
+#endif
+ /* starting the cleanup of fileage now . . . */
+
+ if (fileage != NULL)
+ free_filestruct(fileage);
+
+ /* that is all for now */
+
}
diff -u -b nano-1.1.6/nano.c nano-1.1.6-cvs.debug/nano.c
--- nano-1.1.6/nano.c Sun Feb 24 14:16:39 2002
+++ nano-1.1.6-cvs.debug/nano.c Sun Feb 24 15:32:01 2002
@@ -100,6 +100,8 @@
/* Restore the old term settings */
tcsetattr(0, TCSANOW, &oldterm);
+ thanks_for_the_memories();
+
exit(sigage);
}
@@ -3262,7 +3264,11 @@
/* Look through the main shortcut list to see if we've hit a
shortcut key */
+#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined
(DISABLE_HELP)
for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
+#else
+ for (s = main_list; s != NULL && !keyhandled; s = s->next) {
+#endif
if (kbinput == s->val ||
(s->misc1 && kbinput == s->misc1) ||
(s->misc2 && kbinput == s->misc2)) {
diff -u -b nano-1.1.6/proto.h nano-1.1.6-cvs.debug/proto.h
--- nano-1.1.6/proto.h Sun Feb 24 14:09:55 2002
+++ nano-1.1.6-cvs.debug/proto.h Sun Feb 24 15:32:01 2002
@@ -47,6 +50,7 @@
extern char *last_replace;
#ifndef DISABLE_OPERATINGDIR
extern char *operating_dir;
+extern char *full_operating_dir;
#endif
#ifndef DISABLE_SPELLER
extern char *alt_speller;
@@ -91,6 +95,7 @@
int search_init(int replacing);
int renumber(filestruct * fileptr);
int free_filestruct(filestruct * src);
+int free_shortcutage(shortcut **src);
int xplustabs(void);
int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus);
- Re: [Nano-devel] merged patch, (continued)
Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/21
- Re: [Nano-devel] merged patch, Chris Allegretta, 2002/02/21
- Re: [Nano-devel] merged patch, Chris Allegretta, 2002/02/21
- Re: [Nano-devel] merged patch, Dwayne Rightler, 2002/02/22
- Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/22
- [Nano-devel] Now that we really don't need it . . ., Steven Kneizys, 2002/02/23
- [Nano-devel] small fix: --enable-tiny;question about: check_statusblank();old stuff, Steven Kneizys, 2002/02/23
- [Nano-devel] 1.1.6 mem leaks revisited,
Steven Kneizys <=
- Re: [Nano-devel] 1.1.6 mem leaks revisited, Chris Allegretta, 2002/02/26
Re: [Nano-devel] merged patch, Steven Kneizys, 2002/02/22
Re: [Nano-devel] merged patch, Gareth Pearce, 2002/02/21
Re: [Nano-devel] merged patch, David Lawrence Ramsey, 2002/02/22