Terminal: Fix double-freed memory

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 <superstippi@gmx.de>
This commit is contained in:
Zotyamester 2019-12-17 21:58:38 +00:00 committed by Adrien Destugues
parent eeb89ccd8b
commit a02f7c7bae
1 changed files with 0 additions and 3 deletions

View File

@ -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;