Title: [104189] trunk/Tools
Revision
104189
Author
[email protected]
Date
2012-01-05 11:55:22 -0800 (Thu, 05 Jan 2012)

Log Message

Stop using explicit memory management in WebKitLauncherWin

We now use stack-allocated STL objects instead.

Prep work for <http://webkit.org/b/56571> First argument passed to WebKit.exe is ignored by
Safari

Reviewed by Steve Falkenburg.

* WebKitLauncherWin/WebKitLauncherWin.cpp:
(getStringValue):
(applePathFromRegistry):
(safariInstallDir):
(safariBrowserExe):
(_tWinMain):
Changed to use stack-allocated STL objects instead of malloc/free.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (104188 => 104189)


--- trunk/Tools/ChangeLog	2012-01-05 19:54:46 UTC (rev 104188)
+++ trunk/Tools/ChangeLog	2012-01-05 19:55:22 UTC (rev 104189)
@@ -1,5 +1,24 @@
 2012-01-05  Adam Roben  <[email protected]>
 
+        Stop using explicit memory management in WebKitLauncherWin
+
+        We now use stack-allocated STL objects instead.
+
+        Prep work for <http://webkit.org/b/56571> First argument passed to WebKit.exe is ignored by
+        Safari
+
+        Reviewed by Steve Falkenburg.
+
+        * WebKitLauncherWin/WebKitLauncherWin.cpp:
+        (getStringValue):
+        (applePathFromRegistry):
+        (safariInstallDir):
+        (safariBrowserExe):
+        (_tWinMain):
+        Changed to use stack-allocated STL objects instead of malloc/free.
+
+2012-01-05  Adam Roben  <[email protected]>
+
         Turn WebKitTestRunner into a stub .exe launcher and a .dll that contains all the real code
 
         This allows us to add the Safari and Apple Application Support directories to PATH before

Modified: trunk/Tools/WebKitLauncherWin/WebKitLauncherWin.cpp (104188 => 104189)


--- trunk/Tools/WebKitLauncherWin/WebKitLauncherWin.cpp	2012-01-05 19:54:46 UTC (rev 104188)
+++ trunk/Tools/WebKitLauncherWin/WebKitLauncherWin.cpp	2012-01-05 19:55:22 UTC (rev 104189)
@@ -25,51 +25,55 @@
 
 #include "resource.h"
 #include <shlwapi.h>
+#include <string>
 #include <tchar.h>
+#include <vector>
 #include <windows.h>
 
-static LPTSTR getStringValue(HKEY key, LPCTSTR valueName)
+using namespace std;
+
+typedef basic_string<TCHAR> tstring;
+
+static tstring getStringValue(HKEY key, const tstring& valueName)
 {
     DWORD type = 0;
     DWORD bufferSize = 0;
-    if (RegQueryValueEx(key, valueName, 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
-        return 0;
+    if (RegQueryValueEx(key, valueName.c_str(), 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
+        return tstring();
 
-    LPTSTR buffer = static_cast<LPTSTR>(malloc(bufferSize));
-    if (RegQueryValueEx(key, valueName, 0, &type, reinterpret_cast<LPBYTE>(buffer), &bufferSize) != ERROR_SUCCESS) {
-        free(buffer);
-        return 0;
-    }
+    vector<TCHAR> buffer(bufferSize / sizeof(TCHAR));
+    if (RegQueryValueEx(key, valueName.c_str(), 0, &type, reinterpret_cast<LPBYTE>(&buffer[0]), &bufferSize) != ERROR_SUCCESS)
+        return tstring();
 
-    return buffer;
+    return &buffer[0];
 }
 
-static LPTSTR applePathFromRegistry(LPCTSTR key, LPCTSTR value)
+static tstring applePathFromRegistry(const tstring& key, const tstring& value)
 {
     HKEY applePathKey = 0;
-    LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &applePathKey);
+    LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &applePathKey);
     if (error != ERROR_SUCCESS)
-        return 0;
-    LPTSTR path = getStringValue(applePathKey, value);
+        return tstring();
+    tstring path = getStringValue(applePathKey, value);
     RegCloseKey(applePathKey);
     return path;
 }
 
-static LPTSTR safariInstallDir()
+static tstring safariInstallDir()
 {
     return applePathFromRegistry(TEXT("SOFTWARE\\Apple Computer, Inc.\\Safari"), TEXT("InstallDir"));
 }
 
-static LPTSTR safariBrowserExe()
+static tstring safariBrowserExe()
 {
     return applePathFromRegistry(TEXT("SOFTWARE\\Apple Computer, Inc.\\Safari"), TEXT("BrowserExe"));
 }
 
 int APIENTRY _tWinMain(HINSTANCE instance, HINSTANCE, LPTSTR commandLine, int)
 {
-    LPTSTR path = safariInstallDir();
-    LPTSTR browserExe = safariBrowserExe();
-    if (!path || !browserExe) {
+    tstring path = safariInstallDir();
+    tstring browserExe = safariBrowserExe();
+    if (path.empty() || browserExe.empty()) {
         MessageBox(0, TEXT("Safari must be installed to run a WebKit nightly. You can download Safari from http://www.apple.com/safari/download"), TEXT("Safari not found"), MB_ICONSTOP);
         return 1;
     }
@@ -86,10 +90,8 @@
     STARTUPINFO startupInfo = {0};
     startupInfo.cb = sizeof(startupInfo);
     PROCESS_INFORMATION processInfo = {0};
-    if (!CreateProcess(browserExe, commandLine, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, 0, path, &startupInfo, &processInfo))
+    if (!CreateProcess(browserExe.c_str(), commandLine, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, 0, path.c_str(), &startupInfo, &processInfo))
         MessageBox(0, TEXT("Safari could not be launched. Please make sure you have the latest version of Safari installed and try again. You can download Safari from http://www.apple.com/safari/download"), TEXT("Safari launch failed"), MB_ICONSTOP);
 
-    free(browserExe);
-    free(path);
     return 0;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to