fixed bug that may lead to free()ing static memory
authorHolger Schemel <info@artsoft.org>
Tue, 7 Nov 2017 21:55:42 +0000 (22:55 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:15 +0000 (23:21 +0100)
src/libgame/misc.c

index 72e4f051bf47a44f17b66d28be20fa693e151274..3ff1f8aa9c269d18e84b4bcb8ecf9d806287acd3 100644 (file)
@@ -682,10 +682,16 @@ char *getBasePath(char *filename)
   char *basepath = getStringCopy(filename);
   char *last_separator = getLastPathSeparatorPtr(basepath);
 
-  if (last_separator != NULL)
-    *last_separator = '\0';    /* separator found: strip basename */
-  else
-    basepath = ".";            /* no separator found: use current path */
+  /* if no separator was found, use current directory */
+  if (last_separator == NULL)
+  {
+    free(basepath);
+
+    return getStringCopy(".");
+  }
+
+  /* separator found: strip basename */
+  *last_separator = '\0';
 
   return basepath;
 }