[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] Fix: More on 1.1.6 Memory leaks
From: |
Steven Kneizys |
Subject: |
[Nano-devel] Fix: More on 1.1.6 Memory leaks |
Date: |
Mon, 18 Feb 2002 13:29:48 -0800 (PST) |
--- David Lawrence Ramsey <address@hidden> wrote:
>
> Notice that this snippet of code shows up twice in add_open_file():
>
> /* if open_files->file is NULL at the nrealloc() below, we get a
> segfault
> open_files->file = open_files; */
>
>
> And notice the nmalloc() at this point; it used to be an nrealloc()
> as the comment above said, but it got changed for some reason when
> the memory corruption in null_at() was fixed in 1.1.3.
>
> /* if we're in view mode and updating, the file contents won't
> have changed, so we won't bother resaving the filestruct
> then; otherwise, we will */
> 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);
> do_gotopos(open_files->lineno, open_files->file_current_x,
> open_files->file_current_y, open_files->file_placewewant);
> }
>
> That's my best guess as to the source of the memory leak.
That was about 1/2 of it! If the file names, paths, and previous data
were there they were not freed. The other half was not freeing the
fileage when switching buffers. Minor leak found on checking the
multibuffer name, a path variable was not released. Fix is below :)
(also contains repairs to my previous patch for 1.1.6)
Steve...
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
diff -u nano-1.1.6.new/files.c nano-1.1.6.newer/files.c
--- nano-1.1.6.new/files.c Sun Feb 17 22:02:29 2002
+++ nano-1.1.6.newer/files.c Mon Feb 18 16:02:20 2002
@@ -512,6 +512,8 @@
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
+ open_files->file = NULL;
+ open_files->file_path = NULL;
}
else if (!update) {
@@ -530,12 +532,15 @@
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
+ open_files->file = NULL;
+ open_files->file_path = NULL;
}
/* save current filename */
open_files->data = mallocstrcpy(open_files->data, filename);
/* save the full path location */
+ if (open_files->file_path != NULL) free(open_files->file_path);
open_files->file_path = get_full_path(open_files->data);
/* save current total number of lines */
@@ -562,7 +567,8 @@
if (!(ISSET(VIEW_MODE) && !update)) {
/* save current filestruct and restore full file position
afterward */
- open_files->file = nmalloc(sizeof(filestruct));
+/* open_files->file = nmalloc(sizeof(filestruct));/* */
+ if (open_files->file != NULL) free_filestruct(open_files->file);
open_files->file = copy_filestruct(fileage);
do_gotopos(open_files->lineno, open_files->file_current_x,
open_files->file_current_y, open_files->file_placewewant);
}
@@ -677,6 +683,7 @@
if (!strcmp(tmp->file_path, path)) {
+ free(path);
if (!update)
/* if we're making a new entry and there's an entry with
the same full path, we've found a duplicate */
@@ -696,6 +703,7 @@
}
+ free(path);
return NULL;
}
@@ -779,6 +787,7 @@
}
+ free_filestruct(fileage);/* delete this before reloading */
load_open_file();
#ifdef DEBUG
@@ -841,6 +850,7 @@
}
}
+ free_filestruct(fileage);/* delete this before reloading */
load_open_file();
#ifdef DEBUG
diff -u nano-1.1.6.new/global.c nano-1.1.6.newer/global.c
--- nano-1.1.6.new/global.c Sun Feb 17 21:23:52 2002
+++ nano-1.1.6.newer/global.c Mon Feb 18 15:22:43 2002
@@ -719,17 +719,21 @@
free(answer);
#ifdef ENABLE_MULTIBUFFER
if (open_files != NULL){
+ while (open_files->prev != NULL)
+ open_files = open_files->prev;
while (open_files->next != NULL) {
+ free_filestruct(open_files->file);
+ free(open_files->file_path);
open_files = open_files->next;
free_filestruct(open_files->prev);
}
+ free_filestruct(open_files->file);
+ free(open_files->file_path);
free_filestruct(open_files);
}
#endif
-#ifndef ENABLE_MULTIBUFFER
if (fileage != NULL)
free_filestruct(fileage);
-#endif
if (cutbuffer != NULL)
free_filestruct(cutbuffer);