changeset 233:4045c31c14f9

8136841: Segmentation fault if GPIO input pin is litened Summary: Reorder listener assigment and start notification calls, javanotify is guarded against uninitialized variables. Reviewed-by: alkonsta
author snazarki
date Tue, 22 Sep 2015 18:40:20 +0300
parents d1ca95955562
children 4299ff23b184
files src/se/native/com/oracle/dio/dio_event_queue.cpp src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/native/com/oracle/dio/dio_event_queue.cpp	Tue Sep 15 12:54:17 2015 +0300
+++ b/src/se/native/com/oracle/dio/dio_event_queue.cpp	Tue Sep 22 18:40:20 2015 +0300
@@ -49,7 +49,11 @@
 void event_queue_put_native_event
   (JavaVM* cachedJVM, const char* device_type, const char *payload, int payload_size) {
     JNIEnv* env;
-    cachedJVM->AttachCurrentThread((void**)&env, NULL);
+    if (NULL == eventBuffer) {
+        JAVACALL_REPORT_ERROR(JC_DIO, "Event queue is not initialized properly");
+        return;
+    }
+    cachedJVM->AttachCurrentThread((void **)&env, NULL);
 
     jclass bufferClass = env->GetObjectClass(eventBuffer);
     jmethodID notifyID = bufferClass ? env->GetMethodID(bufferClass, "notify", "()V") :
--- a/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Tue Sep 15 12:54:17 2015 +0300
+++ b/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Tue Sep 22 18:40:20 2015 +0300
@@ -186,6 +186,7 @@
             this.listener = null;
         } else if (this.listener == null) {
             this.listener = listener;
+            EventQueueManager.getInstance().setEventListener(GPIOPin.class, 0, this);
             try {
                 startNoti0();
             } catch (IOException ex) {
@@ -194,7 +195,6 @@
                     ExceptionMessage.format(ExceptionMessage.GPIO_CANNOT_START_NOTIFICATION)
                 );
             }
-            EventQueueManager.getInstance().setEventListener(GPIOPin.class, 0, this);
         } else {
             throw new IllegalStateException (
                 ExceptionMessage.format(ExceptionMessage.GPIO_LISTENER_ALREADY_ASSIGNED)