fix memory leak in allocExec/freeExec (see bug #985)
authorSimon Marlow <simonmar@microsoft.com>
Mon, 5 Feb 2007 10:21:02 +0000 (10:21 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Mon, 5 Feb 2007 10:21:02 +0000 (10:21 +0000)
rts/sm/Storage.c

index 6e862f2..097c727 100644 (file)
@@ -1046,13 +1046,17 @@ void freeExec (void *addr)
     bd->gen_no -= *(StgPtr)p;
     *(StgPtr)p = 0;
 
-    // Free the block if it is empty, but not if it is the block at
-    // the head of the queue.
-    if (bd->gen_no == 0 && bd != exec_block) {
-       debugTrace(DEBUG_gc, "free exec block %p", bd->start);
-        dbl_link_remove(bd, &exec_block);
-       setExecutable(bd->start, bd->blocks * BLOCK_SIZE, rtsFalse);
-       freeGroup(bd);
+    if (bd->gen_no == 0) {
+        // Free the block if it is empty, but not if it is the block at
+        // the head of the queue.
+        if (bd != exec_block) {
+            debugTrace(DEBUG_gc, "free exec block %p", bd->start);
+            dbl_link_remove(bd, &exec_block);
+            setExecutable(bd->start, bd->blocks * BLOCK_SIZE, rtsFalse);
+            freeGroup(bd);
+        } else {
+            bd->free = bd->start;
+        }
     }
 
     RELEASE_SM_LOCK