Fix shell line rendering use of after free.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-09-28 00:39:43 +02:00
parent 6a177d4d79
commit 5cee2e9bc7
1 changed files with 12 additions and 6 deletions

View File

@ -259,9 +259,12 @@ bool show_line_optimized(struct show_line* show_state, const char* line, size_t
show_line_change_cursor(show_state, cursor_wcp);
free(show_state->current_line);
show_state->current_line = strdup(line);
assert(show_state->current_line);
if ( show_state->current_line != line )
{
free(show_state->current_line);
show_state->current_line = strdup(line);
assert(show_state->current_line);
}
show_state->current_cursor = cursor;
return true;
@ -342,9 +345,12 @@ void show_line(struct show_line* show_state, const char* line, size_t cursor)
show_state->wcp_current = wcp;
free(show_state->current_line);
show_state->current_line = strdup(line);
assert(show_state->current_line);
if ( show_state->current_line != line )
{
free(show_state->current_line);
show_state->current_line = strdup(line);
assert(show_state->current_line);
}
show_state->current_cursor = cursor;
show_state->invalidated = false;