From: Benno Schulenberg Date: Fri, 15 Jan 2016 16:44:50 +0000 (+0000) Subject: Freeing the items on the undo stack when a buffer is closed. X-Git-Tag: v2.5.2~68 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f845938e86e8b990d47e524dfeb8faf0ad35736d;p=nano.git 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 --- diff --git a/ChangeLog b/ChangeLog index db8ae682..f4c8a3a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * src/files.c (set_modified): Move this function to its habitat. * src/files.c (open_file): Return the fantastic file descriptor 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 * src/files.c (open_file): Free the full filename in all cases. diff --git a/src/nano.c b/src/nano.c index 05d98ce7..46c78b6b 100644 --- a/src/nano.c +++ b/src/nano.c @@ -561,6 +561,8 @@ void delete_opennode(openfilestruct *fileptr) #ifndef NANO_TINY free(fileptr->current_stat); free(fileptr->lock_filename); + /* Free the undo stack. */ + discard_until(NULL, fileptr); #endif free(fileptr); } diff --git a/src/proto.h b/src/proto.h index d48f04f5..e0842b48 100644 --- a/src/proto.h +++ b/src/proto.h @@ -748,7 +748,7 @@ void new_magicline(void); void remove_magicline(void); void mark_order(const filestruct **top, size_t *top_x, const filestruct **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 update_undo(undo_type action); #endif diff --git a/src/text.c b/src/text.c index d30b8d87..da475b25 100644 --- a/src/text.c +++ b/src/text.c @@ -391,7 +391,7 @@ void do_indent(ssize_t cols) if (indent_changed) { /* Throw away the undo stack, to prevent making mistakes when * the user tries to undo something in the reindented text. */ - discard_until(NULL); + discard_until(NULL, openfile); openfile->current_undo = NULL; /* Mark the file as modified. */ @@ -893,18 +893,18 @@ bool execute_command(const char *command) return TRUE; } -/* Discard undo items that are newer than thisone, or all if NULL. */ -void discard_until(undo *thisone) +/* Discard undo items that are newer than the given one, or all if NULL. */ +void discard_until(const undo *thisitem, openfilestruct *thefile) { - undo *dropit = openfile->undotop; + undo *dropit = thefile->undotop; - while (dropit != NULL && dropit != thisone) { - openfile->undotop = dropit->next; + while (dropit != NULL && dropit != thisitem) { + thefile->undotop = dropit->next; free(dropit->strdata); if (dropit->cutbuffer != NULL) free_filestruct(dropit->cutbuffer); free(dropit); - dropit = openfile->undotop; + dropit = thefile->undotop; } } @@ -922,7 +922,7 @@ void add_undo(undo_type action) return; /* Blow away newer undo items if we add somewhere in the middle. */ - discard_until(u); + discard_until(u, openfile); #ifdef DEBUG fprintf(stderr, " >> Adding an undo...\n"); @@ -2298,7 +2298,7 @@ void do_justify(bool full_justify) #ifndef NANO_TINY /* Throw away the entire undo stack, to prevent a crash when * the user tries to undo something in the justified text. */ - discard_until(NULL); + discard_until(NULL, openfile); openfile->current_undo = NULL; #endif /* Blow away the text in the justify buffer. */