diff --git a/rott/rt_datadir.c b/rott/rt_datadir.c index d55f562..c7589fa 100644 --- a/rott/rt_datadir.c +++ b/rott/rt_datadir.c @@ -209,12 +209,11 @@ char *FindFileByName(const char *name) path = M_StringJoin(datadirs[i], PATH_SEP_STR, name, NULL); probe = M_FileCaseExists(path); + free(path); if (probe != NULL) { return probe; } - - free(path); } // File not found diff --git a/rott/rt_main.c b/rott/rt_main.c index ecbcb3b..eeb25a1 100644 --- a/rott/rt_main.c +++ b/rott/rt_main.c @@ -857,6 +857,11 @@ NoRTC:; newargs [argnum++] = NULL; W_InitMultipleFiles(newargs); + + for (int i = 0; i < argnum; i++) + { + free(newargs[i]); + } } void PlayTurboGame diff --git a/rott/scriplib.c b/rott/scriplib.c index 21c216f..90cd657 100644 --- a/rott/scriplib.c +++ b/rott/scriplib.c @@ -96,11 +96,11 @@ void UnGetToken (void) ============== */ -void GetToken (boolean crossline) +void GetToken(boolean crossline) { - char *token_p; + char *token_p; - if (tokenready) // is a token allready waiting? + if (tokenready) // is a token allready waiting? { tokenready = false; return; @@ -109,31 +109,23 @@ void GetToken (boolean crossline) if (script_p >= scriptend_p) { if (!crossline) - Error ("Line %i is incomplete\nin file %s\n", - scriptline,scriptfilename); + Error("Line %i is incomplete\nin file %s\n", scriptline, scriptfilename); + endofscript = true; return; } -// -// skip space -// -skipspace: - while (*script_p <= 32) + // + // skip space + // + skipspace: + while (script_p < scriptend_p && *script_p <= 32) { - if (script_p >= scriptend_p) - { - if (!crossline) - Error ("Line %i is incomplete\nin file %s\n", - scriptline,scriptfilename); - endofscript = true; - return; - } if (*script_p++ == '\n') { if (!crossline) - Error ("Line %i is incomplete\nin file %s\n", - scriptline,scriptfilename); + Error("Line %i is incomplete\nin file %s\n", scriptline, scriptfilename); + scriptline++; } } @@ -141,40 +133,43 @@ void GetToken (boolean crossline) if (script_p >= scriptend_p) { if (!crossline) - Error ("Line %i is incomplete\nin file %s\n", - scriptline,scriptfilename); + Error("Line %i is incomplete\nin file %s\n", scriptline, scriptfilename); + endofscript = true; return; } - if (*script_p == ';') // semicolon is comment field + if (*script_p == ';') // semicolon is comment field { if (!crossline) - Error ("Line %i is incomplete\nin file %s\n", - scriptline,scriptfilename); - while (*script_p++ != '\n') - if (script_p >= scriptend_p) - { - endofscript = true; - return; - } + Error("Line %i is incomplete\nin file %s\n", scriptline, scriptfilename); + + while (script_p < scriptend_p && *script_p != '\n') + script_p++; + + if (script_p >= scriptend_p) + { + endofscript = true; + return; + } + goto skipspace; } -// -// copy token -// + // + // copy token + // token_p = token; - while ( *script_p > 32 && *script_p != ';') + while (*script_p > 32 && *script_p != ';') { *token_p++ = *script_p++; if (script_p == scriptend_p) break; if (token_p == &token[MAXTOKEN]) - Error ("Token too large on line %i\nin file %s\n", - scriptline,scriptfilename); - } + Error("Token too large on line %i\nin file %s\n", scriptline, + scriptfilename); + } *token_p = 0; }