Bug 1332523 - Add BinaryPath::Get variant that returns a UniquePtr instead of filling a stack buffer. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 13 Jan 2017 09:40:54 +0900
changeset 377758 8c3f028204919bc85aa873a224adbd5686c104ac
parent 377757 e1baf4f6ef960a5638b83505c20342f27b121c12
child 377759 9710f861673f2dc0bd25db1f8fc6d092f06f0e66
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1332523
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1332523 - Add BinaryPath::Get variant that returns a UniquePtr instead of filling a stack buffer. r=bsmedberg
browser/app/nsBrowserApp.cpp
xpcom/build/BinaryPath.h
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -232,25 +232,23 @@ static int do_main(int argc, char* argv[
 #endif
 
   return gBootstrap->XRE_main(argc, argv, config);
 }
 
 static nsresult
 InitXPCOMGlue(const char *argv0)
 {
-  char exePath[MAXPATHLEN];
-
-  nsresult rv = mozilla::BinaryPath::Get(argv0, exePath);
-  if (NS_FAILED(rv)) {
+  UniqueFreePtr<char> exePath = BinaryPath::Get(argv0);
+  if (!exePath) {
     Output("Couldn't find the application directory.\n");
-    return rv;
+    return NS_ERROR_FAILURE;
   }
 
-  gBootstrap = mozilla::GetBootstrap(exePath);
+  gBootstrap = mozilla::GetBootstrap(exePath.get());
   if (!gBootstrap) {
     Output("Couldn't load XPCOM.\n");
     return NS_ERROR_FAILURE;
   }
 
   // This will set this thread as the main thread.
   gBootstrap->NS_LogInit();
 
--- a/xpcom/build/BinaryPath.h
+++ b/xpcom/build/BinaryPath.h
@@ -11,16 +11,18 @@
 #ifdef XP_WIN
 #include <windows.h>
 #elif defined(XP_MACOSX)
 #include <CoreFoundation/CoreFoundation.h>
 #elif defined(XP_UNIX)
 #include <sys/stat.h>
 #include <string.h>
 #endif
+#include "mozilla/UniquePtr.h"
+#include "mozilla/UniquePtrExtensions.h"
 
 namespace mozilla {
 
 class BinaryPath
 {
 public:
 #ifdef XP_WIN
   static nsresult Get(const char* argv0, char aResult[MAXPATHLEN])
@@ -150,16 +152,27 @@ private:
     return NS_ERROR_FAILURE;
   }
 
 #else
 #error Oops, you need platform-specific code here
 #endif
 
 public:
+  static UniqueFreePtr<char> Get(const char *aArgv0)
+  {
+    char path[MAXPATHLEN];
+    if (NS_FAILED(Get(aArgv0, path))) {
+      return nullptr;
+    }
+    UniqueFreePtr<char> result;
+    result.reset(strdup(path));
+    return result;
+  }
+
   static nsresult GetFile(const char* aArgv0, nsIFile** aResult)
   {
     nsCOMPtr<nsIFile> lf;
 #ifdef XP_WIN
     wchar_t exePath[MAXPATHLEN];
     nsresult rv = GetW(aArgv0, exePath);
 #else
     char exePath[MAXPATHLEN];