From 5af778ba7f813eeefe0fedbd366edd6d1236c8b4 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 16 Jun 2018 23:44:28 -0400 Subject: [PATCH 1/5] Fix M_FindResponseFile returning garbage data --- src/m_argv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/m_argv.c b/src/m_argv.c index 859fc9026..e9f086891 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -198,17 +198,16 @@ void M_FindResponseFile(void) k++; } while (k < size); - free(file); - for (k = 0; k < pindex; k++) myargv[indexinfile++] = moreargs[k]; myargc = indexinfile; // display arguments - CONS_Printf(M_GetText("%d command-line args:\n"), myargc); + CONS_Printf(M_GetText("%d command-line args:\n"), myargc-1); // -1 so @ don't actually get counted for for (k = 1; k < myargc; k++) CONS_Printf("%s\n", myargv[k]); break; + free(file); // Needs to be called after everything else, or we would end up with garbage data } -} +} \ No newline at end of file From e95f3eb2063223d7d695973e04c4b8d7595d79ec Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 17 Jun 2018 00:09:35 -0400 Subject: [PATCH 2/5] Update copyright --- src/m_argv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_argv.c b/src/m_argv.c index e9f086891..ac400f673 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -2,7 +2,7 @@ //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2016 by Sonic Team Junior. +// Copyright (C) 1999-2018 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. From 7f11010b42db30bf8f43689340ab6e4ccfcb0217 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 23 Jun 2018 14:39:26 -0400 Subject: [PATCH 3/5] Remove free() call from the function --- src/m_argv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/m_argv.c b/src/m_argv.c index ac400f673..905ac6ab8 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -208,6 +208,5 @@ void M_FindResponseFile(void) CONS_Printf("%s\n", myargv[k]); break; - free(file); // Needs to be called after everything else, or we would end up with garbage data } } \ No newline at end of file From 5c8c35e773997da2a1ffaaf22f0e2ceddd39ffdb Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 23 Jun 2018 15:09:11 -0400 Subject: [PATCH 4/5] Deallocate when I_Quit() is called instead. --- src/sdl/i_system.c | 1 + src/sdl12/i_system.c | 1 + src/win32/win_sys.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e86a39cab..dd42119a2 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2132,6 +2132,7 @@ void I_Quit(void) printf("\r"); ShowEndTxt(); } + free(myargv); // Deallocate allocated memory death: W_Shutdown(); exit(0); diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index ed0db653d..2be6b55f0 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -2301,6 +2301,7 @@ void I_Quit(void) printf("\r"); ShowEndTxt(); } + free(myargv); // Deallocate allocated memory death: W_Shutdown(); #ifdef GP2X diff --git a/src/win32/win_sys.c b/src/win32/win_sys.c index 316da61d4..110eafb7a 100644 --- a/src/win32/win_sys.c +++ b/src/win32/win_sys.c @@ -771,6 +771,7 @@ void I_Quit(void) ShowEndTxt(co); } fflush(stderr); + free(myargv); // Deallocate allocated memory W_Shutdown(); exit(0); } From 08af33c51f7e8b8bc1f71cc63e6a096db03455c4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 23 Nov 2018 19:12:48 +0000 Subject: [PATCH 5/5] Add myargmalloc boolean to detect whether we allocated myargv ourselves or not, so we don't free myargv if we didn't --- src/m_argv.c | 5 +++++ src/m_argv.h | 1 + src/sdl/i_system.c | 3 ++- src/sdl12/i_system.c | 3 ++- src/win32/win_sys.c | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/m_argv.c b/src/m_argv.c index 905ac6ab8..5c5dc37cf 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -25,6 +25,10 @@ INT32 myargc; */ char **myargv; +/** \brief did we alloc myargv ourselves? +*/ +boolean myargmalloc = false; + /** \brief founded the parm */ static INT32 found; @@ -176,6 +180,7 @@ void M_FindResponseFile(void) free(file); I_Error("Not enough memory to read response file"); } + myargmalloc = true; // mark as having been allocated by us memset(myargv, 0, sizeof (char *) * MAXARGVS); myargv[0] = firstargv; diff --git a/src/m_argv.h b/src/m_argv.h index 46ef9a2cf..af346a2c1 100644 --- a/src/m_argv.h +++ b/src/m_argv.h @@ -19,6 +19,7 @@ // extern INT32 myargc; extern char **myargv; +extern boolean myargmalloc; // Returns the position of the given parameter in the arg list (0 if not found). INT32 M_CheckParm(const char *check); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 869fd7d98..2b35ce8b8 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2139,7 +2139,8 @@ void I_Quit(void) printf("\r"); ShowEndTxt(); } - free(myargv); // Deallocate allocated memory + if (myargmalloc) + free(myargv); // Deallocate allocated memory death: W_Shutdown(); exit(0); diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index 2be6b55f0..8729e5921 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -2301,7 +2301,8 @@ void I_Quit(void) printf("\r"); ShowEndTxt(); } - free(myargv); // Deallocate allocated memory + if (myargmalloc) + free(myargv); // Deallocate allocated memory death: W_Shutdown(); #ifdef GP2X diff --git a/src/win32/win_sys.c b/src/win32/win_sys.c index 110eafb7a..77a21f7f3 100644 --- a/src/win32/win_sys.c +++ b/src/win32/win_sys.c @@ -771,7 +771,8 @@ void I_Quit(void) ShowEndTxt(co); } fflush(stderr); - free(myargv); // Deallocate allocated memory + if (myargmalloc) + free(myargv); // Deallocate allocated memory W_Shutdown(); exit(0); }