diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index b1e2b049b4f8..7072e1822971 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,10 @@ +2012-01-12 Janne Blomqvist + Tobias Burnus + + PR libfortran/51803 + * runtime/main.c (store_exe_path): Avoid malloc if getcwd fails or + is not available. + 2012-01-11 Tobias Burnus * runtime/main.c (store_exe_path): Fix absolute path @@ -5,6 +12,7 @@ 2012-01-11 Janne Blomqvist Mike Stump + PR libfortran/51803 * runtime/main.c (store_exe_path): Handle getcwd failure and lack of the function better. diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index 9ee47022cc9b..79659e52bcd2 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -124,12 +124,17 @@ store_exe_path (const char * argv0) #ifdef HAVE_GETCWD cwd = getcwd (buf, sizeof (buf)); - if (!cwd) - cwd = "."; #else - cwd = "."; + cwd = NULL; #endif + if (!cwd) + { + exe_path = argv0; + please_free_exe_path_when_done = 0; + return; + } + /* exe_path will be cwd + "/" + argv[0] + "\0". This will not work if the executable is not in the cwd, but at this point we're out of better ideas. */