Free all the charmaps after parsing

This commit is contained in:
Rangi42
2024-02-19 09:00:15 -05:00
parent 464000bca8
commit ee59f17ea1
4 changed files with 19 additions and 8 deletions

View File

@@ -9,6 +9,7 @@
#define DEFAULT_CHARMAP_NAME "main"
struct Charmap *charmap_New(char const *name, char const *baseName);
void charmap_Cleanup(void);
void charmap_Set(char const *name);
void charmap_Push(void);
void charmap_Pop(void);

View File

@@ -104,6 +104,19 @@ struct Charmap *charmap_New(char const *name, char const *baseName)
return charmap;
}
static void freeCharmap(void *_charmap, void *)
{
struct Charmap *charmap = (struct Charmap *)_charmap;
free(charmap->name);
free(charmap);
}
void charmap_Cleanup(void)
{
hash_ForEach(charmaps, freeCharmap, NULL);
}
void charmap_Set(char const *name)
{
struct Charmap **charmap = (struct Charmap **)hash_GetNode(charmaps, name);

View File

@@ -412,6 +412,9 @@ int main(int argc, char *argv[])
if (yyparse() != 0 && nbErrors == 0)
nbErrors = 1;
// Free all charmaps (they're not needed after parsing)
charmap_Cleanup();
if (dependfile)
fclose(dependfile);
free(targetFileName);

View File

@@ -193,13 +193,6 @@ static void printUsage(void)
stderr);
}
// Cleans up what has been done
// Mostly here to please tools such as `valgrind` so actual errors can be seen
static void cleanup(void)
{
obj_Cleanup();
}
enum ScrambledRegion {
SCRAMBLE_ROMX,
SCRAMBLE_SRAM,
@@ -465,5 +458,6 @@ int main(int argc, char *argv[])
out_WriteFiles();
// Do cleanup before quitting, though.
cleanup();
// Mostly here to please tools such as `valgrind` so actual errors can be seen
obj_Cleanup();
}