Bug 603997: Don't unconditionally use PATH_MAX

Since PATH_MAX is not guaranteed to be defined, unconditionally
using it will cause a build failure on platforms that don't define
it. So stop using it and use dynamic allocation to achieve the same
result.