fixed bug with overwriting level file info from level template
authorHolger Schemel <info@artsoft.org>
Mon, 3 Sep 2018 21:33:02 +0000 (23:33 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 4 Sep 2018 07:02:50 +0000 (09:02 +0200)
This bug (which was causing crashes due to double free()ing strings)
was a nasty side effect of changing string pointers in the file info
structure from using string references (allocated and freed somewhere
else) to copies of strings allocated and freed for each change, while
still copying the file info from the level template over to the file
info of the level file in function "ActivateLevelTemplate()" (causing
duplicates of string pointers which were therefore freed twice).

This bug was most probably the real cause for the problems fixed by
the changes in commit 759e0bea.

src/files.c

index efbc26f8cb2797a1784498ae81fedea88e140acf..21bede9a7be2fbf873b82a6ee3b2ae10e64d0512 100644 (file)
@@ -1915,6 +1915,9 @@ static void ActivateLevelTemplate()
     /* overwrite all individual level settings from template level settings */
     level = level_template;
 
     /* overwrite all individual level settings from template level settings */
     level = level_template;
 
+    /* restore level file info */
+    level.file_info = level_backup.file_info;
+
     /* restore playfield size */
     level.fieldx = level_backup.fieldx;
     level.fieldy = level_backup.fieldy;
     /* restore playfield size */
     level.fieldx = level_backup.fieldx;
     level.fieldy = level_backup.fieldy;