Freeing the items on the undo stack when a buffer is closed.

This fixes Savannah bug #46904 reported by Mike Frysinger.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5567 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2016-01-15 16:44:50 +00:00
parent 38acacb461
commit f845938e86
4 changed files with 15 additions and 10 deletions

View File

@ -3,6 +3,9 @@
* src/files.c (set_modified): Move this function to its habitat. * src/files.c (set_modified): Move this function to its habitat.
* src/files.c (open_file): Return the fantastic file descriptor * src/files.c (open_file): Return the fantastic file descriptor
when opening a non-existent file for reading succeeds. when opening a non-existent file for reading succeeds.
* src/nano.c (delete_opennode), src/text.c (discard_until):
Free the items on the undo stack when a buffer is closed.
This fixes Savannah bug #46904 reported by Mike Frysinger.
2016-01-15 Mike Frysinger <vapier@gentoo.org> 2016-01-15 Mike Frysinger <vapier@gentoo.org>
* src/files.c (open_file): Free the full filename in all cases. * src/files.c (open_file): Free the full filename in all cases.

View File

@ -561,6 +561,8 @@ void delete_opennode(openfilestruct *fileptr)
#ifndef NANO_TINY #ifndef NANO_TINY
free(fileptr->current_stat); free(fileptr->current_stat);
free(fileptr->lock_filename); free(fileptr->lock_filename);
/* Free the undo stack. */
discard_until(NULL, fileptr);
#endif #endif
free(fileptr); free(fileptr);
} }

View File

@ -748,7 +748,7 @@ void new_magicline(void);
void remove_magicline(void); void remove_magicline(void);
void mark_order(const filestruct **top, size_t *top_x, const filestruct void mark_order(const filestruct **top, size_t *top_x, const filestruct
**bot, size_t *bot_x, bool *right_side_up); **bot, size_t *bot_x, bool *right_side_up);
void discard_until(undo *thisone); void discard_until(const undo *thisitem, openfilestruct *thefile);
void add_undo(undo_type action); void add_undo(undo_type action);
void update_undo(undo_type action); void update_undo(undo_type action);
#endif #endif

View File

@ -391,7 +391,7 @@ void do_indent(ssize_t cols)
if (indent_changed) { if (indent_changed) {
/* Throw away the undo stack, to prevent making mistakes when /* Throw away the undo stack, to prevent making mistakes when
* the user tries to undo something in the reindented text. */ * the user tries to undo something in the reindented text. */
discard_until(NULL); discard_until(NULL, openfile);
openfile->current_undo = NULL; openfile->current_undo = NULL;
/* Mark the file as modified. */ /* Mark the file as modified. */
@ -893,18 +893,18 @@ bool execute_command(const char *command)
return TRUE; return TRUE;
} }
/* Discard undo items that are newer than thisone, or all if NULL. */ /* Discard undo items that are newer than the given one, or all if NULL. */
void discard_until(undo *thisone) void discard_until(const undo *thisitem, openfilestruct *thefile)
{ {
undo *dropit = openfile->undotop; undo *dropit = thefile->undotop;
while (dropit != NULL && dropit != thisone) { while (dropit != NULL && dropit != thisitem) {
openfile->undotop = dropit->next; thefile->undotop = dropit->next;
free(dropit->strdata); free(dropit->strdata);
if (dropit->cutbuffer != NULL) if (dropit->cutbuffer != NULL)
free_filestruct(dropit->cutbuffer); free_filestruct(dropit->cutbuffer);
free(dropit); free(dropit);
dropit = openfile->undotop; dropit = thefile->undotop;
} }
} }
@ -922,7 +922,7 @@ void add_undo(undo_type action)
return; return;
/* Blow away newer undo items if we add somewhere in the middle. */ /* Blow away newer undo items if we add somewhere in the middle. */
discard_until(u); discard_until(u, openfile);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " >> Adding an undo...\n"); fprintf(stderr, " >> Adding an undo...\n");
@ -2298,7 +2298,7 @@ void do_justify(bool full_justify)
#ifndef NANO_TINY #ifndef NANO_TINY
/* Throw away the entire undo stack, to prevent a crash when /* Throw away the entire undo stack, to prevent a crash when
* the user tries to undo something in the justified text. */ * the user tries to undo something in the justified text. */
discard_until(NULL); discard_until(NULL, openfile);
openfile->current_undo = NULL; openfile->current_undo = NULL;
#endif #endif
/* Blow away the text in the justify buffer. */ /* Blow away the text in the justify buffer. */