Page 1 of 1

crash when built with -DRO_GAME_DIR=something

Posted: Thu Apr 18, 2019 10:13 pm
by filbo

Code: Select all

$ make sdl2 RO_GAME_DIR=/usr/share/games/rocksndiamonds RW_GAME_DIR=/var/games/rocksndiamonds
$ ./rocksndiamonds
*** Error in `./rocksndiamonds': free(): invalid pointer: 0x0000000000592d38 ***
-- because getProgramMainDataPath() returns RO_BASE_PATH, which is a constant and can't be free()'d in line 521 `checked_free(ro_base_path);'

Code: Select all

$ git diff -U1
diff --git a/src/libgame/setup.c b/src/libgame/setup.c
index 7e87a76..5cdaa87 100644
--- a/src/libgame/setup.c
+++ b/src/libgame/setup.c
@@ -459,3 +459,3 @@ char *getProgramMainDataPath(char *command_filename, char *base_path)
   if (!strEqual(base_path, "."))
-    return base_path;
+    return getStringCopy(base_path);

Re: crash when built with -DRO_GAME_DIR=something

Posted: Thu Apr 18, 2019 11:08 pm
by Holger
Yeah, right -- this (a function than may return a string constant or string copy) was always wrong, but did not cause much harm as long as the result was never properly free()'d.

Fixed using your patch! Thanks!