mirror of git://git.sv.gnu.org/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
This commit is contained in:
parent
38acacb461
commit
f845938e86
|
@ -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 <vapier@gentoo.org>
|
||||
* src/files.c (open_file): Free the full filename in all cases.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
18
src/text.c
18
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. */
|
||||
|
|
Loading…
Reference in New Issue