From: Holger Schemel Date: Tue, 7 Nov 2017 21:55:42 +0000 (+0100) Subject: fixed bug that may lead to free()ing static memory X-Git-Tag: 4.1.0.0~63 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1ae81bd84cbf998cdd03a118e881668ce5a23cf1;p=rocksndiamonds.git fixed bug that may lead to free()ing static memory --- 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; }