8042752: [macosx] NSEvent instances leak throw JNI local references
Reviewed-by: serb, azvegint
--- a/jdk/src/macosx/native/sun/awt/AWTView.m Thu May 08 16:50:42 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m Thu May 08 18:37:34 2014 +0400
@@ -27,6 +27,7 @@
#import <JavaNativeFoundation/JavaNativeFoundation.h>
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
+#import "jni_util.h"
#import "ThreadUtilities.h"
#import "AWTView.h"
@@ -391,14 +392,12 @@
(jint)absP.x, (jint)absP.y,
[event deltaY],
[event deltaX]);
- if (jEvent == nil) {
- // Unable to create event by some reason.
- return;
- }
+ CHECK_NULL(jEvent);
static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
JNFCallVoidMethod(env, m_cPlatformView, jm_deliverMouseEvent, jEvent);
+ (*env)->DeleteLocalRef(env, jEvent);
}
- (void) resetTrackingArea {
@@ -447,20 +446,22 @@
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;)V");
- jobject jevent = JNFNewObject(env, jctor_NSEvent,
+ jobject jEvent = JNFNewObject(env, jctor_NSEvent,
[event type],
[event modifierFlags],
[event keyCode],
characters);
+ CHECK_NULL(jEvent);
static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
"deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
- JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jevent);
+ JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jEvent);
if (characters != NULL) {
(*env)->DeleteLocalRef(env, characters);
}
+ (*env)->DeleteLocalRef(env, jEvent);
}
-(void) deliverResize: (NSRect) rect {
--- a/jdk/src/macosx/native/sun/awt/CTrayIcon.m Thu May 08 16:50:42 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/CTrayIcon.m Thu May 08 18:37:34 2014 +0400
@@ -25,6 +25,7 @@
#import <AppKit/AppKit.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import "jni_util.h"
#import "CTrayIcon.h"
#import "ThreadUtilities.h"
@@ -146,14 +147,12 @@
(jint)absP.x, (jint)absP.y,
[event deltaY],
[event deltaX]);
- if (jEvent == nil) {
- // Unable to create event by some reason.
- return;
- }
+ CHECK_NULL(jEvent);
static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon");
static JNF_MEMBER_CACHE(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
JNFCallVoidMethod(env, peer, jm_handleMouseEvent, jEvent);
+ (*env)->DeleteLocalRef(env, jEvent);
}
@end //AWTTrayIcon