From 1ae81bd84cbf998cdd03a118e881668ce5a23cf1 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 7 Nov 2017 22:55:42 +0100 Subject: [PATCH] fixed bug that may lead to free()ing static memory --- src/libgame/misc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 72e4f051..3ff1f8aa 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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; } -- 2.34.1