* Fix a memory leak regarding implementation of SOC_ (improperly copypasted code from LUA_LoadLump!!)

* Optimise the repeated strlen usage into a single call, which is stored for later.
This commit is contained in:
toaster 2018-10-08 18:50:17 +01:00
parent 12e0222929
commit 1324e0bfcd
2 changed files with 17 additions and 10 deletions

View file

@ -182,19 +182,21 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump)
{
MYFILE f;
char *name;
size_t len;
f.wad = wad;
f.size = W_LumpLengthPwad(wad, lump);
f.data = Z_Malloc(f.size, PU_LUA, NULL);
W_ReadLumpPwad(wad, lump, f.data);
f.curpos = f.data;
name = malloc(strlen(wadfiles[wad]->filename)+10);
len = strlen(wadfiles[wad]->filename);
name = malloc(len+10);
strcpy(name, wadfiles[wad]->filename);
if (!fasticmp(&name[strlen(name) - 4], ".lua")) {
if (!fasticmp(&name[len - 4], ".lua")) {
// If it's not a .lua file, copy the lump name in too.
name[strlen(wadfiles[wad]->filename)] = '|';
M_Memcpy(name+strlen(wadfiles[wad]->filename)+1, wadfiles[wad]->lumpinfo[lump].name, 8);
name[strlen(wadfiles[wad]->filename)+9] = '\0';
name[len] = '|';
M_Memcpy(name+len+1, wadfiles[wad]->lumpinfo[lump].name, 8);
name[len+9] = '\0';
}
LUA_LoadFile(&f, name);

View file

@ -194,16 +194,21 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum)
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump
char *name = malloc(strlen(wadfiles[wadnum]->filename)+10);
size_t len = strlen(wadfiles[wadnum]->filename);
char *name = malloc(len+10);
strcpy(name, wadfiles[wadnum]->filename);
if (!fasticmp(&name[strlen(name) - 4], ".soc")) {
if (!fasticmp(&name[len - 4], ".soc")) {
// If it's not a .soc file, copy the lump name in too.
name[strlen(wadfiles[wadnum]->filename)] = '|';
M_Memcpy(name+strlen(wadfiles[wadnum]->filename)+1, lump_p->name, 8);
name[strlen(wadfiles[wadnum]->filename)+9] = '\0';
name[len] = '|';
M_Memcpy(name+len+1, lump_p->name, 8);
name[len+9] = '\0';
}
CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, lump);
free(name);
}
else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG
{