]> rtime.felk.cvut.cz Git - orte.git/commitdiff
JORTE: fix subscription destruction
authorMartin Vajnar <martin.vajnar@gmail.com>
Fri, 19 Jul 2013 09:20:39 +0000 (11:20 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Mon, 23 Sep 2013 09:06:26 +0000 (11:06 +0200)
Destroy subscription first, then destroy references to objects
in subscription callback. This prevents SEGFAULTs from the receiving
thread, that tries to save received instance to a non-existent object.
DeleteLocalReference was replaced with DeleteGlobalReference, since we are
destroying a global reference. This prevents dvmAbort() being called
on Android. This also fixes a memory leak (the ctx->msg reference was not
deleted).

orte/libjorte/JORTESubscriptionDestroy.c

index 4a6ed3f08c1927e92ffe2980acb4253d5d719117..1cd9c12b7350a60415f570483536316e8a085bb9 100644 (file)
@@ -74,6 +74,19 @@ Java_org_ocera_orte_Subscription_jORTESubscriptionDestroy
      #endif
      break;
     }
+    if(subs_handle)
+    {
+      // call ORTE function
+      b = ORTESubscriptionDestroy((ORTESubscription *) subs_handle);
+      if (b == ORTE_BAD_HANDLE)
+      {
+        printf(":!c: subscription destroy failed! [bad sub handle] \n");
+        break;
+      }
+      #ifdef TEST_STAGE
+        printf(":c: subscription destroy succesfuly.. \n");
+      #endif
+    }
     // get value
     h = (*env)->GetLongField(env, obj, fid);
     if(h)
@@ -86,31 +99,24 @@ Java_org_ocera_orte_Subscription_jORTESubscriptionDestroy
         #ifdef TEST_STAGE
           printf(":c: deleting ctx->obj \n");
         #endif
-        (*env)->DeleteLocalRef(env, ctx->obj);
+        (*env)->DeleteGlobalRef(env, ctx->obj);
       }
       if(ctx->rinfo)
       {
         #ifdef TEST_STAGE
           printf(":c: deleting ctx->rinfo\n");
         #endif
-        (*env)->DeleteLocalRef(env, ctx->rinfo);
+        (*env)->DeleteGlobalRef(env, ctx->rinfo);
       }
-      //
-      free((void*)h);
-    }
-    //
-    if(subs_handle)
-    {
-      // call ORTE function
-      b = ORTESubscriptionDestroy((ORTESubscription *) subs_handle);
-      if (b == ORTE_BAD_HANDLE)
+      if(ctx->msg)
       {
-        printf(":!c: subscription destroy failed! [bad sub handle] \n");
-        break;
+        #ifdef TEST_STAGE
+          printf(":c: deleting ctx->msg\n");
+        #endif
+        (*env)->DeleteGlobalRef(env, ctx->msg);
       }
-      #ifdef TEST_STAGE
-        printf(":c: subscription destroy succesfuly.. \n");
-      #endif
+      //
+      free((void*)h);
     }
     // set flag
     flag_ok = 1;