Fix a memory leak in CON_RESIZEARRAY. This commit also includes an inconsequential dozen or so lines of formatting changes I had done when I stumbled across the bug.

git-svn-id: https://svn.eduke32.com/eduke32@5839 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-08-27 01:42:19 +00:00
parent 3f4a4679ce
commit bf41fc91b0

View file

@ -4012,7 +4012,7 @@ finish_qsprintf:
int const labelNum = *insptr++;
int const lVar2 = *insptr++;
int const sectNum = (tw != g_thisActorVarID) ? Gv_GetVarX(tw) : sprite[vm.spriteNum].sectnum;
int32_t const nValue = Gv_GetVarX(lVar2);
int const nValue = Gv_GetVarX(lVar2);
VM_SetSector(sectNum, labelNum, nValue);
continue;
@ -4707,10 +4707,10 @@ finish_qsprintf:
// OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n",
// aGameArrays[j].szLabel, aGameArrays[j].size, newSize);
intptr_t * const tmpar = oldSize != 0 ? (intptr_t *)Xmalloc(GAR_ELTSZ * oldSize) : NULL;
intptr_t * const pArray = oldSize != 0 ? (intptr_t *)Xmalloc(GAR_ELTSZ * oldSize) : NULL;
if (oldSize != 0)
memcpy(tmpar, aGameArrays[tw].pValues, GAR_ELTSZ * oldSize);
Bmemcpy(pArray, aGameArrays[tw].pValues, GAR_ELTSZ * oldSize);
Baligned_free(aGameArrays[tw].pValues);
@ -4718,10 +4718,12 @@ finish_qsprintf:
aGameArrays[tw].size = newSize;
if (oldSize != 0)
memcpy(aGameArrays[tw].pValues, tmpar, GAR_ELTSZ * min(oldSize, newSize));
Bmemcpy(aGameArrays[tw].pValues, pArray, GAR_ELTSZ * min(oldSize, newSize));
if (newSize > oldSize)
memset(&aGameArrays[tw].pValues[oldSize], 0, GAR_ELTSZ * (newSize - oldSize));
Bmemset(&aGameArrays[tw].pValues[oldSize], 0, GAR_ELTSZ * (newSize - oldSize));
Bfree(pArray);
}
continue;
}