From e2b916a91fcd0563853e45a8a8c509d63876e8e5 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 30 Jan 2011 22:37:59 +0000 Subject: [PATCH] Console segfault fix ed.str is deallocated when console_ui returns. Dereferencing the returned pointer to ed.str therefore results in bad things. --- src/interface.c | 2 +- src/main.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/interface.c b/src/interface.c index e3450074a..d020bf6fb 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3883,7 +3883,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show currentcommand->prev_command = last_command; currentcommand->command = mystrdup(ed.str); last_command = currentcommand; - return ed.str; + return currentcommand->command; } if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE) { diff --git a/src/main.c b/src/main.c index d20fb35e0..a3891d097 100644 --- a/src/main.c +++ b/src/main.c @@ -1707,6 +1707,7 @@ int main(int argc, char *argv[]) //char error[255] = "error!"; sys_pause = 1; console = console_ui(vid_buf,error); + console = mystrdup(console); strcpy(error,""); if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0) { @@ -1716,6 +1717,7 @@ int main(int argc, char *argv[]) console5 = strtok(NULL, " "); if(strcmp(console2, "quit")==0) { + free(console); break; } else if(strcmp(console2, "load")==0 && console3) @@ -1955,6 +1957,7 @@ int main(int argc, char *argv[]) else sprintf(error, "Invalid Command", console2); } + free(console); if(!console_mode) hud_enable = 1; }