summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Gayed <ggayed>2010-07-27 16:52:45 +0000
committerGrant Gayed <ggayed>2010-07-27 16:52:45 +0000
commit4193e9c18adbebaa72eb2578a5d7e7cf79f692fe (patch)
tree5b5efd692f5d61dc532c020423d604c00d3772c9
parent9ba7e6c23c78c599edae57e98b09012100af0810 (diff)
downloadeclipse.platform.swt-4193e9c18adbebaa72eb2578a5d7e7cf79f692fe.tar.gz
eclipse.platform.swt-4193e9c18adbebaa72eb2578a5d7e7cf79f692fe.tar.xz
eclipse.platform.swt-4193e9c18adbebaa72eb2578a5d7e7cf79f692fe.zip
316252 - Wrong usage of C.free()
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java8
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.cpp42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java87
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java8
9 files changed, 150 insertions, 31 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java
index 83933ff64f..9b32d7b748 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/carbon/org/eclipse/swt/browser/MozillaDelegate.java
@@ -41,6 +41,10 @@ static Browser findBrowser (int handle) {
return null;
}
+static String getLibraryName () {
+ return "libxpcom.dylib"; //$NON-NLS-1$
+}
+
static char[] mbcsToWcs (String codePage, byte [] buffer) {
int encoding = OS.CFStringGetSystemEncoding ();
int cfstring = OS.CFStringCreateWithBytes (OS.kCFAllocatorDefault, buffer, buffer.length, encoding, false);
@@ -202,10 +206,6 @@ String getJSLibraryName () {
return "libmozjs.dylib"; //$NON-NLS-1$
}
-String getLibraryName () {
- return "libxpcom.dylib"; //$NON-NLS-1$
-}
-
String getProfilePath () {
String baseDir = System.getProperty ("user.home"); //$NON-NLS-1$
return baseDir + Mozilla.SEPARATOR_OS + ".mozilla" + Mozilla.SEPARATOR_OS + "eclipse"; //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java
index 3f1848c934..40ef94fc13 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/cocoa/org/eclipse/swt/browser/MozillaDelegate.java
@@ -32,6 +32,10 @@ static Browser findBrowser (int /*long*/ handle) {
return (Browser)display.findWidget (handle);
}
+static String getLibraryName () {
+ return "libxpcom.dylib"; //$NON-NLS-1$
+}
+
static char[] mbcsToWcs (String codePage, byte [] buffer) {
// int encoding = OS.CFStringGetSystemEncoding ();
// int cfstring = OS.CFStringCreateWithBytes (OS.kCFAllocatorDefault, buffer, buffer.length, encoding, false);
@@ -101,10 +105,6 @@ String getJSLibraryName () {
return "libmozjs.dylib"; //$NON-NLS-1$
}
-String getLibraryName () {
- return "libxpcom.dylib"; //$NON-NLS-1$
-}
-
String getProfilePath () {
String baseDir = System.getProperty ("user.home"); //$NON-NLS-1$
return baseDir + Mozilla.SEPARATOR_OS + ".mozilla" + Mozilla.SEPARATOR_OS + "eclipse"; //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.cpp b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.cpp
index c27048e48f..32741cf67a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.cpp
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.cpp
@@ -85,4 +85,46 @@ fail:
}
#endif
+#ifndef NO__1NS_1Free
+JNIEXPORT jint JNICALL XPCOM_NATIVE(_1NS_1Free)
+ (JNIEnv *env, jclass that, jbyteArray mozillaPath, jintLong arg0)
+{
+ jbyte *lpmozillaPath=NULL;
+ jint rc = 0;
+ XPCOM_NATIVE_ENTER(env, that, _1NS_1Free_FUNC);
+ if (mozillaPath) if ((lpmozillaPath = env->GetByteArrayElements(mozillaPath, NULL)) == NULL) goto fail;
+/*
+ NS_Free((void*)arg0);
+*/
+ {
+
+#ifdef _WIN32
+ LOAD_FUNCTION(fp, NS_Free)
+ if (fp) {
+ ((jint (*)(void *))fp)((void *)arg0);
+ rc = 1;
+ }
+#else
+#define CALLING_CONVENTION
+ static int initialized = 0;
+ static void *fp = NULL;
+ if (!initialized) {
+ void* handle = dlopen((const char *)lpmozillaPath, RTLD_LAZY);
+ if (handle) {
+ fp = dlsym(handle, "NS_Free");
+ }
+ initialized = 1;
+ }
+ if (fp) {
+ ((jint (CALLING_CONVENTION*)(void *))fp)((void *)arg0);
+ rc = 1;
+ }
+#endif /* _WIN32 */
+ }
+fail:
+ if (mozillaPath && lpmozillaPath) env->ReleaseByteArrayElements(mozillaPath, lpmozillaPath, 0);
+ XPCOM_NATIVE_EXIT(env, that, _1NS_1Free_FUNC);
+ return rc;
+}
+#endif
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.h b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.h
index c11fe30889..21bc33838d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_custom.h
@@ -12,6 +12,7 @@
#ifdef _WIN32
#include <windows.h>
#define JS_EvaluateUCScriptForPrincipals_LIB "js3250.dll"
+#define NS_Free_LIB "xpcom.dll"
#define XP_WIN
#else
#include <dlfcn.h>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
index e02e7f2dd9..30d6b71a3a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java
@@ -65,6 +65,8 @@ class Mozilla extends WebBrowser {
static boolean Initialized, IsPre_1_8, IsPre_1_9, PerformedVersionCheck, XPCOMWasGlued, XPCOMInitWasGlued;
static String oldProxyHostFTP, oldProxyHostHTTP, oldProxyHostSSL;
static int oldProxyPortFTP = -1, oldProxyPortHTTP = -1, oldProxyPortSSL = -1, oldProxyType = -1;
+ static byte[] pathBytes_JSEvaluateUCScriptForPrincipals;
+ static byte[] pathBytes_NSFree;
/* XULRunner detect constants */
static final String GRERANGE_LOWER = "1.8.1.2"; //$NON-NLS-1$
@@ -438,7 +440,24 @@ class Mozilla extends WebBrowser {
int length = C.strlen (cookieString);
bytes = new byte[length];
XPCOM.memmove (bytes, cookieString, length);
- C.free (cookieString);
+
+ /*
+ * NS_Free was introduced in mozilla 1.8, prior to this the standard free() call
+ * was to be used. Try to free the cookie string with NS_Free first, and if it fails
+ * then assume that an older mozilla is being used, and use C's free() instead.
+ */
+ if (pathBytes_NSFree == null) {
+ String mozillaPath = getMozillaPath () + MozillaDelegate.getLibraryName () + '\0';
+ try {
+ pathBytes_NSFree = mozillaPath.getBytes ("UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ pathBytes_NSFree = mozillaPath.getBytes ();
+ }
+ }
+ if (!XPCOM.NS_Free (pathBytes_NSFree, cookieString)) {
+ C.free (cookieString);
+ }
+
String allCookies = new String (MozillaDelegate.mbcsToWcs (null, bytes));
StringTokenizer tokenizer = new StringTokenizer (allCookies, ";"); //$NON-NLS-1$
while (tokenizer.hasMoreTokens ()) {
@@ -560,7 +579,7 @@ public boolean create (Composite parent, int style) {
*/
}
} else {
- mozillaPath += SEPARATOR_OS + delegate.getLibraryName ();
+ mozillaPath += SEPARATOR_OS + MozillaDelegate.getLibraryName ();
isXULRunner = true;
}
@@ -600,7 +619,7 @@ public boolean create (Composite parent, int style) {
if (mozillaPath.indexOf("xulrunner") == -1) { //$NON-NLS-1$
isXULRunner = false;
} else {
- mozillaPath += SEPARATOR_OS + delegate.getLibraryName ();
+ mozillaPath += SEPARATOR_OS + MozillaDelegate.getLibraryName ();
path = MozillaDelegate.wcsToMbcs (null, mozillaPath, true);
rc = XPCOMInit.XPCOMGlueStartup (path);
if (rc != XPCOM.NS_OK) {
@@ -1226,12 +1245,13 @@ public boolean execute (String script) {
int /*long*/ principals = result[0];
result[0] = 0;
principal.Release ();
- String mozillaPath = LocationProvider.mozillaPath + delegate.getJSLibraryName () + '\0';
- byte[] pathBytes = null;
- try {
- pathBytes = mozillaPath.getBytes ("UTF-8"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
- pathBytes = mozillaPath.getBytes ();
+ if (pathBytes_JSEvaluateUCScriptForPrincipals == null) {
+ String mozillaPath = getMozillaPath () + delegate.getJSLibraryName () + '\0';
+ try {
+ pathBytes_JSEvaluateUCScriptForPrincipals = mozillaPath.getBytes ("UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ pathBytes_JSEvaluateUCScriptForPrincipals = mozillaPath.getBytes ();
+ }
}
aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CONTEXTSTACK_CONTRACTID, true);
@@ -1244,7 +1264,7 @@ public boolean execute (String script) {
result[0] = 0;
rc = stack.Push (nativeContext);
if (rc != XPCOM.NS_OK) error (rc);
- boolean success = XPCOM.JS_EvaluateUCScriptForPrincipals (pathBytes, nativeContext, globalJSObject, principals, scriptChars, length, urlbytes, 0, result) != 0;
+ boolean success = XPCOM.JS_EvaluateUCScriptForPrincipals (pathBytes_JSEvaluateUCScriptForPrincipals, nativeContext, globalJSObject, principals, scriptChars, length, urlbytes, 0, result) != 0;
result[0] = 0;
rc = stack.Pop (result);
if (rc != XPCOM.NS_OK) error (rc);
@@ -1345,6 +1365,53 @@ public String getBrowserType () {
return "mozilla"; //$NON-NLS-1$
}
+static String getMozillaPath () {
+ if (LocationProvider != null) return LocationProvider.mozillaPath;
+ if (!Initialized) return "";
+
+ int /*long*/[] result = new int /*long*/[1];
+ int rc = XPCOM.NS_GetServiceManager (result);
+ if (rc != XPCOM.NS_OK) error (rc);
+ if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+
+ nsIServiceManager serviceManager = new nsIServiceManager (result[0]);
+ result[0] = 0;
+ byte[] buffer = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_DIRECTORYSERVICE_CONTRACTID, true);
+ rc = serviceManager.GetServiceByContractID (buffer, nsIDirectoryService.NS_IDIRECTORYSERVICE_IID, result);
+ if (rc != XPCOM.NS_OK) error (rc);
+ if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+ serviceManager.Release();
+
+ nsIDirectoryService directoryService = new nsIDirectoryService (result[0]);
+ result[0] = 0;
+ rc = directoryService.QueryInterface (nsIProperties.NS_IPROPERTIES_IID, result);
+ if (rc != XPCOM.NS_OK) error (rc);
+ if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+ directoryService.Release ();
+
+ nsIProperties properties = new nsIProperties (result[0]);
+ result[0] = 0;
+ buffer = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_GRE_DIR, true);
+ rc = properties.Get (buffer, nsIFile.NS_IFILE_IID, result);
+ if (rc != XPCOM.NS_OK) error (rc);
+ if (result[0] == 0) error (XPCOM.NS_NOINTERFACE);
+ properties.Release ();
+
+ nsIFile mozillaDir = new nsIFile (result[0]);
+ result[0] = 0;
+ int /*long*/ path = XPCOM.nsEmbedCString_new ();
+ rc = mozillaDir.GetNativePath (path);
+ if (rc != XPCOM.NS_OK) error (rc);
+ int length = XPCOM.nsEmbedCString_Length (path);
+ int /*long*/ ptr = XPCOM.nsEmbedCString_get (path);
+ buffer = new byte[length];
+ XPCOM.memmove (buffer, ptr, length);
+ XPCOM.nsEmbedCString_delete (path);
+ mozillaDir.Release ();
+
+ return new String (MozillaDelegate.mbcsToWcs (null, buffer)) + SEPARATOR_OS;
+}
+
int getNextFunctionIndex () {
return NextJSFunctionIndex++;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
index 23d3a6465a..79be3c2d27 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java
@@ -166,7 +166,16 @@ public static final int JS_EvaluateUCScriptForPrincipals(byte[] mozillaPath, int
lock.unlock();
}
}
-
+/** @method flags=no_gen */
+public static final native boolean _NS_Free(byte[] mozillaPath, int /*long*/ aPtr);
+public static final boolean NS_Free(byte[] mozillaPath, int /*long*/ aPtr) {
+ lock.lock();
+ try {
+ return _NS_Free(mozillaPath, aPtr);
+ } finally {
+ lock.unlock();
+ }
+}
/** @param result cast=(nsIComponentManager**) */
public static final native int _NS_GetComponentManager(int /*long*/[] result);
public static final int NS_GetComponentManager(int /*long*/[] result) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java
index 2b5f92e137..e2dda62421 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/gtk/org/eclipse/swt/browser/MozillaDelegate.java
@@ -68,6 +68,10 @@ static Browser findBrowser (int /*long*/ handle) {
return (Browser)display.findWidget (parent);
}
+static String getLibraryName () {
+ return "libxpcom.so"; //$NON-NLS-1$
+}
+
static char[] mbcsToWcs (String codePage, byte [] buffer) {
return Converter.mbcsToWcs (codePage, buffer);
}
@@ -104,10 +108,6 @@ String getJSLibraryName () {
return "libmozjs.so"; //$NON-NLS-1$
}
-String getLibraryName () {
- return "libxpcom.so"; //$NON-NLS-1$
-}
-
String getProfilePath () {
String baseDir = System.getProperty ("user.home"); //$NON-NLS-1$
return baseDir + Mozilla.SEPARATOR_OS + ".mozilla" + Mozilla.SEPARATOR_OS + "eclipse"; //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java
index 33a3a91cc8..3a6c5bdd27 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/motif/org/eclipse/swt/browser/MozillaDelegate.java
@@ -77,6 +77,10 @@ static Browser findBrowser (Control control, int gtkHandle) {
return null;
}
+static String getLibraryName () {
+ return "libxpcom.so"; //$NON-NLS-1$
+}
+
static char[] mbcsToWcs (String codePage, byte [] buffer) {
return Converter.mbcsToWcs (codePage, buffer);
}
@@ -116,10 +120,6 @@ String getJSLibraryName () {
return "libmozjs.so"; //$NON-NLS-1$
}
-String getLibraryName () {
- return "libxpcom.so"; //$NON-NLS-1$
-}
-
String getProfilePath () {
String baseDir = System.getProperty ("user.home"); //$NON-NLS-1$
return baseDir + Mozilla.SEPARATOR_OS + ".mozilla" + Mozilla.SEPARATOR_OS + "eclipse"; //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java
index 8317a40d36..f7bb342053 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/win32/org/eclipse/swt/browser/MozillaDelegate.java
@@ -31,6 +31,10 @@ static Browser findBrowser (int /*long*/ handle) {
return (Browser)display.findWidget (handle);
}
+static String getLibraryName () {
+ return "xpcom.dll"; //$NON-NLS-1$
+}
+
static char[] mbcsToWcs (String codePage, byte[] buffer) {
char[] chars = new char[buffer.length];
int charCount = OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, buffer, buffer.length, chars, chars.length);
@@ -90,10 +94,6 @@ String getJSLibraryName () {
return "js3250.dll"; //$NON-NLS-1$
}
-String getLibraryName () {
- return "xpcom.dll"; //$NON-NLS-1$
-}
-
String getProfilePath () {
String baseDir;
/* Use the character encoding for the default locale */