Fix a crash when pathToLocalResource fails and a leak
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2008 18:14:34 +0000 (18:14 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2008 18:14:34 +0000 (18:14 +0000)
         Reviewed by Darin.

         * DumpRenderTree/LayoutTestController.cpp:
         (pathToLocalResourceCallback): Dont leak the JSStringRef, and make
         sure not to pass null to JSValueMakeString.
         * DumpRenderTree/win/LayoutTestControllerWin.cpp:
         (LayoutTestController::pathToLocalResource): Print an error message if
         the conversion fails so it's clear what happened.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29406 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp

index 37c3967..f272fda 100644 (file)
@@ -1,3 +1,16 @@
+2008-01-11  Adam Roben  <aroben@apple.com>
+
+        Fix a crash when pathToLocalResource fails and a leak
+
+        Reviewed by Darin.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (pathToLocalResourceCallback): Dont leak the JSStringRef, and make
+        sure not to pass null to JSValueMakeString.
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::pathToLocalResource): Print an error message if
+        the conversion fails so it's clear what happened.
+
 2008-01-11  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by John Sullivan.
index 2767285..303efe3 100644 (file)
@@ -145,7 +145,11 @@ static JSValueRef pathToLocalResourceCallback(JSContextRef context, JSObjectRef
     JSRetainPtr<JSStringRef> localPath(Adopt, JSValueToStringCopy(context, arguments[0], exception));
     ASSERT(!*exception);
 
-    return JSValueMakeString(context, controller->pathToLocalResource(context, localPath.get()));
+    JSRetainPtr<JSStringRef> convertedPath(Adopt, controller->pathToLocalResource(context, localPath.get()));
+    if (!convertedPath)
+        return JSValueMakeUndefined(context);
+
+    return JSValueMakeString(context, convertedPath.get());
 }
 
 static JSValueRef repaintSweepHorizontallyCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
index 589e33a..2d8b4f9 100644 (file)
@@ -149,9 +149,13 @@ void LayoutTestController::notifyDone()
 
 JSStringRef LayoutTestController::pathToLocalResource(JSContextRef context, JSStringRef url)
 {
+    wstring input(JSStringGetCharactersPtr(url), JSStringGetLength(url));
+
     wstring localPath;
-    if (!resolveCygwinPath(wstring(JSStringGetCharactersPtr(url), JSStringGetLength(url)), localPath))
+    if (!resolveCygwinPath(input, localPath)) {
+        printf("ERROR: Failed to resolve Cygwin path %S\n", input.c_str());
         return 0;
+    }
 
     return JSStringCreateWithCharacters(localPath.c_str(), localPath.length());
 }