Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Iiiirk. It leaks
[simgrid.git] / src / gras / Msg / msg.c
index 0d9f2f8..ab0f1fb 100644 (file)
@@ -8,6 +8,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/ex.h"
+#include "xbt/ex_interface.h"
 #include "gras/Msg/msg_private.h"
 #include "gras/Virtu/virtu_interface.h"
 #include "gras/DataDesc/datadesc_interface.h"
@@ -139,7 +140,7 @@ gras_msgtype_declare_ext(const char           *name,
   } CATCH(e) {
     if (e.category != not_found_error)
       RETHROW;
-    xbt_ex_free(e);
+    xbt_ex_free(&e);
   }
 
   if (found) {
@@ -228,7 +229,7 @@ gras_msgtype_t gras_msgtype_by_namev(const char      *name,
   TRY {
     res = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set, namev);
   } CATCH(e) {
-    xbt_ex_free(e);
+    xbt_ex_free(&e);
     THROW1(not_found_error,0,"No registred message of that name: %s",name);
   }
   if (name != namev) 
@@ -373,7 +374,7 @@ gras_msg_handle(double timeOut) {
   
   double          untiltimer;
    
-  int             cpt;
+  int             cpt, ran_ok;
 
   s_gras_msg_t    msg;
 
@@ -411,7 +412,7 @@ gras_msg_handle(double timeOut) {
     } CATCH(e) {
       if (e.category != timeout_error)
        RETHROW;
-      xbt_ex_free(e);
+      xbt_ex_free(&e);
       timeouted = 1;
     }
 
@@ -448,7 +449,8 @@ gras_msg_handle(double timeOut) {
        
      } else {
        /* select timeouted, and no timer elapsed. Nothing to do */
-       THROW0(timeout_error, 0, "No new message or timer");
+       THROW1(timeout_error, 0, "No new message or timer (delay was %f)",
+             timeOut);
      }
      
   }
@@ -475,14 +477,17 @@ gras_msg_handle(double timeOut) {
   switch (msg.kind) {
   case e_gras_msg_kind_oneway:
   case e_gras_msg_kind_rpccall:
+    ran_ok=0;
     TRY {
       xbt_dynar_foreach(list->cbs,cpt,cb) { 
-       VERB3("Use the callback #%d (@%p) for incomming msg %s",
-             cpt+1,cb,msg.type->name);
-       if ((*cb)(&ctx,msg.payl)) {
-         /* cb handled the message */
-         free(msg.payl);
-         return;
+       if (!ran_ok) {
+         VERB3("Use the callback #%d (@%p) for incomming msg %s",
+               cpt+1,cb,msg.type->name);
+         if ((*cb)(&ctx,msg.payl)) {
+           /* cb handled the message */
+           free(msg.payl);
+           ran_ok = 1;
+         }
        }
       }
     } CATCH(e) {
@@ -491,26 +496,25 @@ gras_msg_handle(double timeOut) {
        /* The callback raised an exception, propagate it on the network */
        if (!e.remote) { /* the exception is born on this machine */
          e.host = (char*)gras_os_myname();
-#ifdef HAVE_EXECINFO_H
-         e.bt_strings = backtrace_symbols (e.bt, e.used);
-#endif
+         xbt_ex_setup_backtrace(&e);
        } 
-       gras_msg_send_ext(msg.expe, e_gras_msg_kind_rpcerror,
-                         msg.ID, msg.type, &e);
-       INFO4("Propagated %s exception from '%s' RPC cb back to %s:%d",
+       VERB4("Propagate %s exception from '%s' RPC cb back to %s:%d",
              (e.remote ? "remote" : "local"),
              msg.type->name,
              gras_socket_peer_name(msg.expe),
              gras_socket_peer_port(msg.expe));
-       e.host = NULL;
-       xbt_ex_free(e);
-       return;
+       gras_msg_send_ext(msg.expe, e_gras_msg_kind_rpcerror,
+                         msg.ID, msg.type, &e);
+       xbt_ex_free(&e);
+       ran_ok=1;
+      } else {
+       RETHROW0("Callback raised an exception: %s");
       }
-      RETHROW;
     }
+    if (!ran_ok)
+      THROW1(mismatch_error,0,
+            "Message '%s' refused by all registered callbacks", msg.type->name);
     /* FIXME: gras_datadesc_free not implemented => leaking the payload */
-    THROW1(mismatch_error,0,
-          "Message '%s' refused by all registered callbacks", msg.type->name);
     break;