diff options
author | Silenio Quarti <silenio> | 2009-10-01 21:21:51 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2009-10-01 21:21:51 +0000 |
commit | e69ccdf91eaf47c7d23ca34831636ebd90362b25 (patch) | |
tree | f4357a72d40c7730bebdbd14977ecfd0581d2d66 | |
parent | 6384119f0991b9686159e4c1ab4031958e1a87bf (diff) | |
download | eclipse.platform.swt-e69ccdf91eaf47c7d23ca34831636ebd90362b25.tar.gz eclipse.platform.swt-e69ccdf91eaf47c7d23ca34831636ebd90362b25.tar.xz eclipse.platform.swt-e69ccdf91eaf47c7d23ca34831636ebd90362b25.zip |
280277 - possible leak in FileDialog (plus leak in Program)
6 files changed, 54 insertions, 24 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c index f845790ea9..1027b1524f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os.c @@ -17,11 +17,15 @@ #ifndef NO_AECoerceDesc JNIEXPORT jint JNICALL OS_NATIVE(AECoerceDesc) - (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2) { + AEDesc _arg2, *lparg2=NULL; jint rc = 0; OS_NATIVE_ENTER(env, that, AECoerceDesc_FUNC); - rc = (jint)AECoerceDesc((AEDesc *)arg0, arg1, (AEDesc *)arg2); + if (arg2) if ((lparg2 = getAEDescFields(env, arg2, &_arg2)) == NULL) goto fail; + rc = (jint)AECoerceDesc((AEDesc *)arg0, arg1, (AEDesc *)lparg2); +fail: + if (arg2 && lparg2) setAEDescFields(env, arg2, lparg2); OS_NATIVE_EXIT(env, that, AECoerceDesc_FUNC); return rc; } @@ -83,15 +87,18 @@ fail: #ifndef NO_AEGetDescData JNIEXPORT jint JNICALL OS_NATIVE(AEGetDescData) - (JNIEnv *env, jclass that, jint arg0, jbyteArray arg1, jint arg2) + (JNIEnv *env, jclass that, jobject arg0, jbyteArray arg1, jint arg2) { + AEDesc _arg0, *lparg0=NULL; jbyte *lparg1=NULL; jint rc = 0; OS_NATIVE_ENTER(env, that, AEGetDescData_FUNC); + if (arg0) if ((lparg0 = getAEDescFields(env, arg0, &_arg0)) == NULL) goto fail; if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; - rc = (jint)AEGetDescData((AEDesc *)arg0, (void *)lparg1, arg2); + rc = (jint)AEGetDescData((AEDesc *)lparg0, (void *)lparg1, arg2); fail: if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + if (arg0 && lparg0) setAEDescFields(env, arg0, lparg0); OS_NATIVE_EXIT(env, that, AEGetDescData_FUNC); return rc; } @@ -13581,6 +13588,18 @@ JNIEXPORT jint JNICALL OS_NATIVE(kCFRunLoopDefaultMode) } #endif +#ifndef NO_kCFTypeArrayCallBacks +JNIEXPORT jint JNICALL OS_NATIVE(kCFTypeArrayCallBacks) + (JNIEnv *env, jclass that) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, kCFTypeArrayCallBacks_FUNC); + rc = (jint)&kCFTypeArrayCallBacks; + OS_NATIVE_EXIT(env, that, kCFTypeArrayCallBacks_FUNC); + return rc; +} +#endif + #ifndef NO_kFontPanelAttributeSizesKey JNIEXPORT jint JNICALL OS_NATIVE(kFontPanelAttributeSizesKey) (JNIEnv *env, jclass that) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.c index 3e06a61962..0b9cd7fea3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.c @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 989; -int OS_nativeFunctionCallCount[989]; +int OS_nativeFunctionCount = 990; +int OS_nativeFunctionCallCount[990]; char * OS_nativeFunctionNames[] = { "AECoerceDesc", "AECountItems", @@ -976,6 +976,7 @@ char * OS_nativeFunctionNames[] = { "kCFNumberFormatterDecimalSeparator", "kCFRunLoopCommonModes", "kCFRunLoopDefaultMode", + "kCFTypeArrayCallBacks", "kFontPanelAttributeSizesKey", "kFontPanelAttributeTagsKey", "kFontPanelAttributeValuesKey", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.h index 122f4cfa77..a9301ce99c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/library/os_stats.h @@ -984,6 +984,7 @@ typedef enum { kCFNumberFormatterDecimalSeparator_FUNC, kCFRunLoopCommonModes_FUNC, kCFRunLoopDefaultMode_FUNC, + kCFTypeArrayCallBacks_FUNC, kFontPanelAttributeSizesKey_FUNC, kFontPanelAttributeTagsKey_FUNC, kFontPanelAttributeValuesKey_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java index 02a0ac3d80..74a58bbc17 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java @@ -1070,6 +1070,8 @@ public static final native boolean __BIG_ENDIAN__(); public static final native int kCFRunLoopCommonModes(); /** @method flags=const */ public static final native int kCFRunLoopDefaultMode(); +/** @method flags=const address */ +public static final native int kCFTypeArrayCallBacks(); /** @method flags=const */ public static final native int kFontPanelAttributesKey(); /** @method flags=const */ @@ -1098,7 +1100,7 @@ public static final native int AECountItems(AEDesc theAEDescList, int[] theCount * @param theAEDesc cast=(AEDesc *) * @param result cast=(AEDesc *) */ -public static final native int AECoerceDesc(int theAEDesc, int toType, int result); +public static final native int AECoerceDesc(int theAEDesc, int toType, AEDesc result); /** * @param typeCode cast=(DescType) * @param dataPtr cast=(const void *) @@ -1110,7 +1112,7 @@ public static final native int AEDisposeDesc(AEDesc theAEDesc); * @param theAEDesc cast=(AEDesc *) * @param dataPtr cast=(void *) */ -public static final native int AEGetDescData(int theAEDesc, byte[] dataPtr, int maximumSize); +public static final native int AEGetDescData(AEDesc theAEDesc, byte[] dataPtr, int maximumSize); /** * @param theAEDescList cast=(const AEDescList *) * @param desiredType cast=(DescType) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java index 896fbb70e9..e6599715b8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/carbon/org/eclipse/swt/program/Program.java @@ -434,11 +434,12 @@ public boolean execute (String fileName) { int unescapedStr = OS.CFStringCreateWithCharacters(0, unescapedChars, unescapedChars.length); int escapedStr = OS.CFURLCreateStringByAddingPercentEscapes(OS.kCFAllocatorDefault, str, unescapedStr, 0, OS.kCFStringEncodingUTF8); if (escapedStr != 0) { - int urls = OS.CFArrayCreateMutable(OS.kCFAllocatorDefault, 1, 0); + int urls = OS.CFArrayCreateMutable(OS.kCFAllocatorDefault, 1, OS.kCFTypeArrayCallBacks ()); if (urls != 0) { int url = OS.CFURLCreateWithString(OS.kCFAllocatorDefault, escapedStr, 0); if (url != 0) { OS.CFArrayAppendValue(urls, url); + OS.CFRelease(url); rc = OS.LSOpenURLsWithRole(urls, OS.kLSRolesAll, 0, params, null, 0); } OS.CFRelease(urls); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java index 914f6d09b7..fa88421851 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/FileDialog.java @@ -201,14 +201,16 @@ int eventProc (int callBackSelector, int callBackParms, int callBackUD) { } int filterProc (int theItem, int infoPtr, int callBackUD, int filterMode) { + int result = 1; if (filterMode == OS.kNavFilteringBrowserList) { if (filterExtensions != null && 0 <= filterIndex && filterIndex < filterExtensions.length) { NavFileOrFolderInfo info = new NavFileOrFolderInfo(); OS.memmove (info, infoPtr, NavFileOrFolderInfo.sizeof); if (!info.isFolder) { - OS.AECoerceDesc (theItem, OS.typeFSRef, theItem); + AEDesc desc = new AEDesc(); + OS.AECoerceDesc (theItem, OS.typeFSRef, desc); byte [] fsRef = new byte [80]; - if (OS.AEGetDescData (theItem, fsRef, fsRef.length) == OS.noErr) { + if (OS.AEGetDescData (desc, fsRef, fsRef.length) == OS.noErr) { int url = OS.CFURLCreateFromFSRef (OS.kCFAllocatorDefault, fsRef); if (url != 0) { int ext = OS.CFURLCopyPathExtension (url); @@ -224,23 +226,30 @@ int filterProc (int theItem, int infoPtr, int callBackUD, int filterMode) { String extension = new String (buffer); String extensions = filterExtensions [filterIndex]; int start = 0, length = extensions.length (); + result = 0; while (start < length) { int index = extensions.indexOf (EXTENSION_SEPARATOR, start); if (index == -1) index = length; String filter = extensions.substring (start, index).trim (); - if (filter.equals ("*") || filter.equals ("*.*")) return 1; + if (filter.equals ("*") || filter.equals ("*.*")) { + result = 1; + break; + } if (filter.startsWith ("*.")) filter = filter.substring (2); - if (filter.toLowerCase ().equals(extension.toLowerCase ())) return 1; + if (filter.toLowerCase ().equals(extension.toLowerCase ())) { + result = 1; + break; + } start = index + 1; } - return 0; } } } + OS.AEDisposeDesc(desc); } } } - return 1; + return result; } String getString (int cfString) { @@ -296,7 +305,7 @@ public String open () { int [] outDialog = new int [1]; int filterProc = 0, eventProc = 0; if (filterExtensions != null && filterExtensions.length != 0) { - extensions = options.popupExtension = OS.CFArrayCreateMutable (OS.kCFAllocatorDefault, filterExtensions.length, 0); + extensions = options.popupExtension = OS.CFArrayCreateMutable (OS.kCFAllocatorDefault, filterExtensions.length, OS.kCFTypeArrayCallBacks ()); for (int i = 0; i < filterExtensions.length; i++) { String str = filterExtensions [i]; if (filterNames != null && filterNames.length > i) { @@ -305,7 +314,10 @@ public String open () { char [] chars = new char [str.length ()]; str.getChars (0, chars.length, chars, 0); int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, chars, chars.length); - if (ptr != 0) OS.CFArrayAppendValue (extensions, ptr); + if (ptr != 0) { + OS.CFArrayAppendValue (extensions, ptr); + OS.CFRelease(ptr); + } } if ((style & SWT.SAVE) == 0) { filterCallback = new Callback (this, "filterProc", 4); @@ -468,13 +480,7 @@ public String open () { if (titlePtr != 0) OS.CFRelease (titlePtr); if (fileNamePtr != 0) OS.CFRelease (fileNamePtr); if (outDialog [0] != 0) OS.NavDialogDispose (outDialog [0]); - if (extensions != 0) { - int count = OS.CFArrayGetCount (extensions); - for (int i = 0; i < count; i++) { - OS.CFRelease (OS.CFArrayGetValueAtIndex (extensions, i)); - } - OS.CFRelease (extensions); - } + if (extensions != 0) OS.CFRelease (extensions); if (filterCallback != null) filterCallback.dispose(); if (eventCallback != null) eventCallback.dispose(); return fullPath; |