diff --git a/src/files.c b/src/files.c
index 22fe6ecca021dffa9b1d882c71aea000c76b2519..471420c7c2ccd970cd69d6300360517764f4fe65 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1398,7 +1398,7 @@ char *get_full_path(const char *origpath)
 
     while (d_here == NULL && attempts < 20) {
 	IGNORE_CALL_RESULT(chdir(".."));
-	d_here = getcwd(NULL, PATH_MAX + 1);
+	d_here = getcwd(currentdir, PATH_MAX + 1);
 	attempts++;
     }