Skip to content
Snippets Groups Projects
Commit 21685ca7 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Fixed minor memoryleak in getcwd.

Rev: src/modules/files/efuns.c:1.29
parent 51c05767
No related branches found
No related tags found
No related merge requests found
...@@ -457,8 +457,8 @@ void f_cd(INT32 args) ...@@ -457,8 +457,8 @@ void f_cd(INT32 args)
void f_getcwd(INT32 args) void f_getcwd(INT32 args)
{ {
char *e; char *e;
#if defined(HAVE_WORKING_GETCWD) || !defined(HAVE_GETWD)
char *tmp; char *tmp;
#if defined(HAVE_WORKING_GETCWD) || !defined(HAVE_GETWD)
INT32 size; INT32 size;
size=1000; size=1000;
...@@ -467,6 +467,7 @@ void f_getcwd(INT32 args) ...@@ -467,6 +467,7 @@ void f_getcwd(INT32 args)
e=(char *)getcwd(tmp,1000); e=(char *)getcwd(tmp,1000);
if (e || errno!=ERANGE) break; if (e || errno!=ERANGE) break;
free((char *)tmp); free((char *)tmp);
tmp=0;
size*=2; size*=2;
} while (size < 10000); } while (size < 10000);
#else #else
...@@ -474,12 +475,16 @@ void f_getcwd(INT32 args) ...@@ -474,12 +475,16 @@ void f_getcwd(INT32 args)
#ifndef MAXPATHLEN #ifndef MAXPATHLEN
#define MAXPATHLEN 32768 #define MAXPATHLEN 32768
#endif #endif
tmp=xalloc(MAXPATHLEN+1);
THREADS_ALLOW(); THREADS_ALLOW();
e=(char *)getwd((char *)malloc(MAXPATHLEN+1)); e=(char *)getwd(tmp);
THREADS_DISALLOW(); THREADS_DISALLOW();
#endif #endif
if(!e) if(!e) {
if (tmp)
free(tmp);
error("Failed to fetch current path.\n"); error("Failed to fetch current path.\n");
}
pop_n_elems(args); pop_n_elems(args);
push_string(make_shared_string(e)); push_string(make_shared_string(e));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment