From 637b76b582af29099e387271f9935b9a5e1da3f2 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 2 Jul 2014 20:52:27 +0000 Subject: [PATCH] Freeing the cutbuffer after use. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5055 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 +++- src/text.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 440a274b..f16633ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,10 @@ 2014-07-02 Mark Majeres * src/text.c (undo_cut, redo_cut, update_undo): Handle the - cases of cutting-from-cursor-to-end-of-line properly. + cases of cutting-from-cursor-to-end-of-line correctly. * src/nano.c (do_input): Don't preserve the cutbuffer when CUT_TO_END is toggled -- it would intermix two cut types. + * src/text.c (redo_cut, do_undo, do_redo): Don't forget to + free the cutbuffer after use. 2014-07-02 Benno Schulenberg * src/proto.h: Add a typedef for a pointer to a function. diff --git a/src/text.c b/src/text.c index 8cb4de36..807701ae 100644 --- a/src/text.c +++ b/src/text.c @@ -399,6 +399,10 @@ void redo_cut(undo *u) if (!u->cutbuffer) return; + filestruct *oldcutbuffer = cutbuffer, *oldcutbottom = cutbottom; + cutbuffer = NULL; + cutbottom = NULL; + goto_line_posx(u->lineno, u->begin); if (ISSET(NO_NEWLINES) && openfile->current->lineno != u->lineno) { @@ -416,6 +420,11 @@ void redo_cut(undo *u) openfile->mark_begin = NULL; openfile->mark_begin_x = 0; edit_refresh_needed = TRUE; + + if (cutbuffer != NULL) + free_filestruct(cutbuffer); + cutbuffer = oldcutbuffer; + cutbottom = oldcutbottom; } /* Undo the last thing(s) we did. */ @@ -525,6 +534,8 @@ void do_undo(void) openfile->mark_set = TRUE; goto_line_posx(u->lineno, u->begin); cut_marked(); + if (u->cutbuffer != NULL) + free_filestruct(u->cutbuffer); u->cutbuffer = cutbuffer; u->cutbottom = cutbottom; cutbuffer = oldcutbuffer; @@ -656,6 +667,8 @@ void do_redo(void) redidmsg = _("text insert"); goto_line_posx(u->lineno, u->begin); copy_from_filestruct(u->cutbuffer); + free_filestruct(u->cutbuffer); + u->cutbuffer = NULL; break; default: redidmsg = _("Internal error: unknown type. Please save your work."); @@ -924,6 +937,7 @@ void add_undo(undo_type current_action) break; #endif /* !DISABLE_WRAPPING */ case INSERT: + break; case REPLACE: data = mallocstrcpy(NULL, fs->current->data); u->strdata = data;