throwTo: unlock the MSG_THROWTO object before returning (#6103)
authorSimon Marlow <marlowsd@gmail.com>
Tue, 5 Jun 2012 08:05:47 +0000 (09:05 +0100)
committerPaolo Capriotti <p.capriotti@gmail.com>
Fri, 8 Jun 2012 14:47:50 +0000 (15:47 +0100)
MERGED from commit 20ba7f1a7a7b05acd81124f1567a3a103bcd0d1b

rts/RaiseAsync.c

index c14b411..9e5a8c3 100644 (file)
@@ -156,8 +156,7 @@ throwTo (Capability *cap,   // the Capability we hold
     MessageThrowTo *msg;
 
     msg = (MessageThrowTo *) allocate(cap, sizeofW(MessageThrowTo));
-    // message starts locked; the caller has to unlock it when it is
-    // ready.
+    // the message starts locked; see below
     SET_HDR(msg, &stg_WHITEHOLE_info, CCS_SYSTEM);
     msg->source      = source;
     msg->target      = target;
@@ -166,9 +165,16 @@ throwTo (Capability *cap,  // the Capability we hold
     switch (throwToMsg(cap, msg))
     {
     case THROWTO_SUCCESS:
+        // unlock the message now, otherwise we leave a WHITEHOLE in
+        // the heap (#6103)
+        SET_HDR(msg, &stg_MSG_THROWTO_info, CCS_SYSTEM);
         return NULL;
+
     case THROWTO_BLOCKED:
     default:
+        // the caller will unlock the message when it is ready.  We
+        // cannot unlock it yet, because the calling thread will need
+        // to tidy up its state first.
         return msg;
     }
 }