From 1b5ec7017da1829cb17347b7684855ea60be1f00 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 22 Jun 2010 13:14:03 -0700 Subject: [PATCH] Don't use NULL in realpath() on darwin, doesn't work in older versions Thanks to Peter Griess for the bug report. --- src/platform_darwin.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/platform_darwin.cc b/src/platform_darwin.cc index cf0ac71..2ff43f2 100644 --- a/src/platform_darwin.cc +++ b/src/platform_darwin.cc @@ -4,6 +4,7 @@ #include #include #include /* _NSGetExecutablePath */ +#include /* PATH_MAX */ namespace node { @@ -31,10 +32,16 @@ int OS::GetExecutablePath(char* buffer, size_t* size) { uint32_t usize = *size; int result = _NSGetExecutablePath(buffer, &usize); if (result) return result; - char *path = realpath(buffer, NULL); - if (path == NULL) return -1; - strncpy(buffer, path, *size); - free(path); + + char *path = new char[2*PATH_MAX]; + + char *fullpath = realpath(buffer, path); + if (fullpath == NULL) { + delete [] path; + return -1; + } + strncpy(buffer, fullpath, *size); + delete [] fullpath; *size = strlen(buffer); return 0; } -- 2.7.4