Browse Source

b=535194, r=mfinkle, Crash on Mac when registering unknown protocol handler

matthew.gertner@gmail.com 15 years ago
parent
commit
183625aa53
1 changed files with 16 additions and 11 deletions
  1. 16 11
      components/src/mac/nsDesktopEnvironmentMac.mm

+ 16 - 11
components/src/mac/nsDesktopEnvironmentMac.mm

@@ -307,18 +307,23 @@ NS_IMETHODIMP nsDesktopEnvironment::GetDefaultApplicationForURIScheme(const nsAS
   ::CFRelease(tempURL);
   ::CFRelease(urlString);
   
-  CFStringRef leafName = ::CFURLCopyLastPathComponent(appURL);
-  CFRange extension = ::CFStringFind(leafName, CFSTR(".app"), 0);
-  if (extension.location == kCFNotFound) {
-    // Fail if we haven't found an app bundle
-    return NS_ERROR_FAILURE;
-  }
+  if (appURL) {
+    CFStringRef leafName = ::CFURLCopyLastPathComponent(appURL);
+    CFRange extension = ::CFStringFind(leafName, CFSTR(".app"), 0);
+    if (extension.location == kCFNotFound) {
+      // Fail if we haven't found an app bundle
+      return NS_ERROR_FAILURE;
+    }
 
-  PRUnichar* buffer = new PRUnichar[extension.location+1];
-  ::CFStringGetCharacters(leafName, CFRangeMake(0, extension.location), buffer);
-  buffer[extension.location] = 0;
-  _retval = buffer;
-  delete [] buffer;
+    PRUnichar* buffer = new PRUnichar[extension.location+1];
+    ::CFStringGetCharacters(leafName, CFRangeMake(0, extension.location), buffer);
+    buffer[extension.location] = 0;
+    _retval = buffer;
+    delete [] buffer;
+  }
+  else {
+    _retval = EmptyString();
+  }
 
   return err == noErr ? NS_OK : NS_ERROR_FAILURE;
 }