◐ Shell
clean mode source ↗

Issue 6976: getcwd hangs and leaks mem on Solaris <= 9 in very long file name case

test_posix hung on Solaris 9 ... traced to getcwd test hanging.

This in turn was traced to the very long filename case...
It seems posixmodule was modified (since py2.4.3 at least) 
to retry getcwd with a bigger buffer if ERANGE occurs.  

However on Solaris 9 its not documented that ERANGE also
occurs if getcwd(3) can't cope with the path length, even
if the buffer is big enough.  This causes posix_getcwd() to
loop malloc'ing a bigger buffer, forever.

I enclose a patch that limits the damage, to 1Mbyte at least.
(not sure if more recent Solaris 9 patches than we have
provide another solution)

On Solaris 10, there is no problem as the getcwd() is implemented
as a system call.