From a02f7c7baec10508f955e604849f240e3d5288a8 Mon Sep 17 00:00:00 2001 From: Zotyamester Date: Tue, 17 Dec 2019 21:58:38 +0000 Subject: [PATCH] Terminal: Fix double-freed memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base problem was, that every time I opened KeyMap while a Terminal was opened too, it eventually crashed. I followed along the trace and found that the code first frees the keymap and keymapchars in the _UpdateKeymap() and then calls SetKeymap for every tab opened which also tries to free the old keymap and keymapchars. TermWindow's _UpdateKeymap() method first frees the old keymap and keymapchars: delete fKeymap; delete[] fKeymapChars; and then calls SetKeyMap for every tab which tries to free the old keymap and keymapchars again: for (int32 i = 0; i < fTabView->CountTabs(); i++) { TermView* view = _TermViewAt(i); view->SetKeymap(fKeymap, fKeymapChars); } So TermView simply is not responsible for the memory, it merily has a pointer. Fixes #15502. Change-Id: Id08c863d811fbb72cce9be4c8fff2d3eb5f0064f Reviewed-on: https://review.haiku-os.org/c/haiku/+/2037 Reviewed-by: Stephan Aßmus --- src/apps/terminal/TermView.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index fd604be7ae..3c2232f880 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -732,9 +732,6 @@ TermView::SetEncoding(int encoding) void TermView::SetKeymap(const key_map* keymap, const char* chars) { - delete fKeymap; - delete[] fKeymapChars; - fKeymap = keymap; fKeymapChars = chars;