mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Merge pull request #408 from ISSOtm/plumbing
Fix memory leaks with macro args
This commit is contained in:
@@ -63,7 +63,6 @@ void sym_AddNewMacroArg(char *s);
|
|||||||
void sym_SaveCurrentMacroArgs(char *save[]);
|
void sym_SaveCurrentMacroArgs(char *save[]);
|
||||||
void sym_RestoreCurrentMacroArgs(char *save[]);
|
void sym_RestoreCurrentMacroArgs(char *save[]);
|
||||||
void sym_UseNewMacroArgs(void);
|
void sym_UseNewMacroArgs(void);
|
||||||
void sym_FreeCurrentMacroArgs(void);
|
|
||||||
void sym_AddEqu(char *tzSym, int32_t value);
|
void sym_AddEqu(char *tzSym, int32_t value);
|
||||||
void sym_AddSet(char *tzSym, int32_t value);
|
void sym_AddSet(char *tzSym, int32_t value);
|
||||||
void sym_Init(void);
|
void sym_Init(void);
|
||||||
|
|||||||
@@ -128,13 +128,9 @@ static int32_t popcontext(void)
|
|||||||
if (nCurrentStatus == STAT_isInclude)
|
if (nCurrentStatus == STAT_isInclude)
|
||||||
fclose(pCurrentFile);
|
fclose(pCurrentFile);
|
||||||
|
|
||||||
if (nCurrentStatus == STAT_isMacro) {
|
if (nCurrentStatus == STAT_isMacro
|
||||||
sym_FreeCurrentMacroArgs();
|
|| nCurrentStatus == STAT_isREPTBlock)
|
||||||
nLineNo += 1;
|
nLineNo++;
|
||||||
}
|
|
||||||
|
|
||||||
if (nCurrentStatus == STAT_isREPTBlock)
|
|
||||||
nLineNo += 1;
|
|
||||||
|
|
||||||
CurrentFlexHandle = pLastFile->FlexHandle;
|
CurrentFlexHandle = pLastFile->FlexHandle;
|
||||||
strcpy((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
|
strcpy((char *)tzCurrentFileName, (char *)pLastFile->tzFileName);
|
||||||
@@ -385,8 +381,8 @@ void fstk_RunString(char *s)
|
|||||||
void fstk_RunRept(uint32_t count)
|
void fstk_RunRept(uint32_t count)
|
||||||
{
|
{
|
||||||
if (count) {
|
if (count) {
|
||||||
pushcontext();
|
|
||||||
sym_UseCurrentMacroArgs();
|
sym_UseCurrentMacroArgs();
|
||||||
|
pushcontext();
|
||||||
sym_SetMacroArgID(nMacroCount++);
|
sym_SetMacroArgID(nMacroCount++);
|
||||||
sym_UseNewMacroArgs();
|
sym_UseNewMacroArgs();
|
||||||
nCurrentREPTBlockCount = count;
|
nCurrentREPTBlockCount = count;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ int32_t Callback_NARG(unused_ struct sSymbol *sym)
|
|||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
||||||
while (currentmacroargs[i] && i < MAXMACROARGS)
|
while (currentmacroargs[i] && i < MAXMACROARGS)
|
||||||
i += 1;
|
i++;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ void sym_ShiftCurrentMacroArgs(void)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
free(currentmacroargs[0]);
|
free(currentmacroargs[0]);
|
||||||
for (i = 0; i < MAXMACROARGS - 1; i += 1)
|
for (i = 0; i < MAXMACROARGS - 1; i++)
|
||||||
currentmacroargs[i] = currentmacroargs[i + 1];
|
currentmacroargs[i] = currentmacroargs[i + 1];
|
||||||
|
|
||||||
currentmacroargs[MAXMACROARGS - 1] = NULL;
|
currentmacroargs[MAXMACROARGS - 1] = NULL;
|
||||||
@@ -383,7 +383,8 @@ void sym_UseNewMacroArgs(void)
|
|||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
for (i = 0; i <= MAXMACROARGS; i += 1) {
|
for (i = 0; i <= MAXMACROARGS; i++) {
|
||||||
|
free(currentmacroargs[i]);
|
||||||
currentmacroargs[i] = newmacroargs[i];
|
currentmacroargs[i] = newmacroargs[i];
|
||||||
newmacroargs[i] = NULL;
|
newmacroargs[i] = NULL;
|
||||||
}
|
}
|
||||||
@@ -393,25 +394,19 @@ void sym_SaveCurrentMacroArgs(char *save[])
|
|||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
for (i = 0; i <= MAXMACROARGS; i += 1)
|
for (i = 0; i <= MAXMACROARGS; i++) {
|
||||||
save[i] = currentmacroargs[i];
|
save[i] = currentmacroargs[i];
|
||||||
|
currentmacroargs[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sym_RestoreCurrentMacroArgs(char *save[])
|
void sym_RestoreCurrentMacroArgs(char *save[])
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
for (i = 0; i <= MAXMACROARGS; i += 1)
|
for (i = 0; i <= MAXMACROARGS; i++) {
|
||||||
currentmacroargs[i] = save[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void sym_FreeCurrentMacroArgs(void)
|
|
||||||
{
|
|
||||||
int32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i <= MAXMACROARGS; i += 1) {
|
|
||||||
free(currentmacroargs[i]);
|
free(currentmacroargs[i]);
|
||||||
currentmacroargs[i] = NULL;
|
currentmacroargs[i] = save[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,7 +415,7 @@ void sym_AddNewMacroArg(char *s)
|
|||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
|
|
||||||
while (i < MAXMACROARGS && newmacroargs[i] != NULL)
|
while (i < MAXMACROARGS && newmacroargs[i] != NULL)
|
||||||
i += 1;
|
i++;
|
||||||
|
|
||||||
if (i < MAXMACROARGS) {
|
if (i < MAXMACROARGS) {
|
||||||
if (s)
|
if (s)
|
||||||
@@ -444,7 +439,7 @@ void sym_UseCurrentMacroArgs(void)
|
|||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
for (i = 1; i <= MAXMACROARGS; i += 1)
|
for (i = 1; i <= MAXMACROARGS; i++)
|
||||||
sym_AddNewMacroArg(sym_FindMacroArg(i));
|
sym_AddNewMacroArg(sym_FindMacroArg(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,12 +766,12 @@ void sym_Init(void)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
for (i = 0; i < MAXMACROARGS; i += 1) {
|
for (i = 0; i < MAXMACROARGS; i++) {
|
||||||
currentmacroargs[i] = NULL;
|
currentmacroargs[i] = NULL;
|
||||||
newmacroargs[i] = NULL;
|
newmacroargs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < HASHSIZE; i += 1)
|
for (i = 0; i < HASHSIZE; i++)
|
||||||
tHashedSymbols[i] = NULL;
|
tHashedSymbols[i] = NULL;
|
||||||
|
|
||||||
sym_AddReloc("@");
|
sym_AddReloc("@");
|
||||||
|
|||||||
Reference in New Issue
Block a user