Fix double free in osdcmd_do() and clean up the variable definitions while we're there

git-svn-id: https://svn.eduke32.com/eduke32@7084 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-10-25 23:29:25 +00:00
parent 4bb9a4b792
commit 03332e8812

View file

@ -9081,24 +9081,20 @@ static int32_t osdcmd_disasm(osdfuncparm_t const * const parm)
static int32_t osdcmd_do(osdfuncparm_t const * const parm) static int32_t osdcmd_do(osdfuncparm_t const * const parm)
{ {
intptr_t oscrofs;
char *tp;
int32_t i, j, slen, ofs, dontsavehist;
int32_t onumconstants=g_numSavedConstants;
if (parm->numparms==0) if (parm->numparms==0)
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;
oscrofs = (g_scriptPtr-apScript); int32_t onumconstants = g_numSavedConstants;
ofs = 2*(parm->numparms>0); // true if "do" command intptr_t oscrofs = (g_scriptPtr-apScript);
slen = Bstrlen(parm->raw+ofs); int32_t ofs = 2 * (parm->numparms > 0); // true if "do" command
tp = (char *)Xmalloc(slen+2); int32_t slen = Bstrlen(parm->raw + ofs);
char * tp = (char *)Xmalloc(slen+2);
Bmemcpy(tp, parm->raw+ofs, slen); Bmemcpy(tp, parm->raw+ofs, slen);
// M32script call from 'special functions' menu // M32script call from 'special functions' menu
dontsavehist = (slen==0 || tp[0]==' '); int32_t dontsavehist = (slen == 0 || tp[0] == ' ');
// needed so that subsequent commands won't execute old stuff. // needed so that subsequent commands won't execute old stuff.
tp[slen] = '\n'; tp[slen] = '\n';
@ -9108,8 +9104,8 @@ static int32_t osdcmd_do(osdfuncparm_t const * const parm)
C_Compile(tp, 0); C_Compile(tp, 0);
if (parm->numparms>=0) if (parm->numparms >= 0)
Bfree(tp); DO_FREE_AND_NULL(tp);
if (g_numCompilerErrors) if (g_numCompilerErrors)
{ {
@ -9118,10 +9114,6 @@ static int32_t osdcmd_do(osdfuncparm_t const * const parm)
return OSDCMD_OK; return OSDCMD_OK;
} }
for (i=0,j=0; i<MAXEVENTS; i++)
if (aEventOffsets[i]>=0)
j++;
if (g_didDefineSomething == 0) if (g_didDefineSomething == 0)
{ {
g_numSavedConstants = onumconstants; g_numSavedConstants = onumconstants;