Here's another Valgrind report:

==15692== 736 bytes in 1 blocks are definitely lost in loss record 2 of 4
==15692==    at 0x40206D5: calloc (vg_replace_malloc.c:279)
==15692==    by 0x41E82AE: mem_sys_allocate_zeroed (memory.c:79)
==15692==    by 0x41E7BA1: Parrot_alloc_context (register.c:355)
==15692==    by 0x41E761A: create_initial_context (register.c:136)
==15692==    by 0x41E5AEF: make_interpreter (inter_create.c:122)
==15692==    by 0x424308E: Parrot_new (embed.c:48)
==15692==    by 0x804A433: main (main.c:514)

Here's a patch which appears to do the right thing.

-- c

=== src/register.c
==================================================================
--- src/register.c	(revision 2241)
+++ src/register.c	(local)
@@ -111,6 +111,7 @@
         }
     }
     mem_sys_free(interp->ctx_mem.free_list);
+    mem_sys_free(CONTEXT(interp->ctx));
 }
 
 void
@@ -163,7 +164,7 @@
 =item C<void Parrot_free_context(Interp *, parrot_context_t *ctxp, int re_use)>
 
 Free the context. If C<re_use> is true, this function is called by a
-return continuation invoke, else from the destructur of a continuation.
+return continuation invoke, else from the destructor of a continuation.
 
 =item C<void Parrot_pop_context(Interp *)>
 
@@ -313,6 +314,7 @@
 {
     struct Parrot_Context *old, *ctx;
     void *ptr, *p;
+    int copied_context = 0;
 
     /*
      * TODO (OPT) if we allocate a new context due to a self-recursive call
@@ -346,8 +348,10 @@
     }
     else {
         const size_t to_alloc = reg_alloc + ALIGNED_CTX_SIZE;
-        if (old)
-            ptr = mem_sys_allocate(to_alloc);
+        if (old) {
+            ptr            = mem_sys_allocate(to_alloc);
+            copied_context = 1;
+        }
         else
             ptr = mem_sys_allocate_zeroed(to_alloc);
     }
@@ -366,6 +370,8 @@
     /* this points to S0 */
     interp->ctx.bp_ps.regs_s = (STRING**)((char*)p + size_nip);
     init_context(interp, ctx, old);
+    if (copied_context)
+        Parrot_free_context(interp, old, 0);
     return ctx;
 }
 

Reply via email to