* 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.
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
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. */
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;
}
}
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");
#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. */