summary refs log tree commit diff
path: root/src/save.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/save.c')
-rw-r--r--src/save.c9
1 files changed, 6 insertions, 3 deletions
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);
 }