From 93ccfeeb9032eec91e0a4e5053f6646a5c73fe2d Mon Sep 17 00:00:00 2001 From: zlago Date: Thu, 26 Dec 2024 00:07:12 +0100 Subject: bugfixes --- src/save.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/save.c') diff --git a/src/save.c b/src/save.c index 9baf981..faeb8d1 100644 --- a/src/save.c +++ b/src/save.c @@ -19,11 +19,14 @@ int game_save(FILE *file) { return 0; } +static char *level = NULL; // hack to not leak memory + int game_load(FILE *file) { size_t filesize, len; - char *filedata = util_loadFile(file, &filesize); // hack: we leak a tiny bit of memory here + char *filedata = util_loadFile(file, &filesize); fclose(file); - char *level = filedata; + free(level); + level = filedata; len = strnlen(filedata, filesize); if (len == filesize) { fputs("invalid save format\n", stderr); @@ -43,6 +46,6 @@ int game_load(FILE *file) { return 1; } player_property(next_entities.player, "y", filedata); - level = realloc(level, strlen(level) + 1); + level = realloc(level, strlen(level) + 1); // this line looks fucking stupid out of context return game_load_level(level); } -- cgit 1.4.1-2-gfad0