This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: Stop SAVEFREEOP from leaking slabs
authorFather Chrysostomos <sprout@cpan.org>
Mon, 5 Nov 2012 01:44:06 +0000 (17:44 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 5 Nov 2012 06:45:35 +0000 (22:45 -0800)
When a CV is freed prematurely, it cleans up its op slab.  But
SAVEFREEOP may cause the savestack to point to an op in that slab
after the CV has been freed, so SAVEFREEOP is allowed to coun-
termand the freeing of the slab.  Every op that is not on the
savestack is freed.

The reference count of the slab was being left off by one.  The result
was that when the stack unwinding freed the op, it would leave the
slab behind and leak it.

op.c

diff --git a/op.c b/op.c
index b5ecb6d..488665f 100644 (file)
--- a/op.c
+++ b/op.c
@@ -391,6 +391,8 @@ Perl_opslab_force_free(pTHX_ OPSLAB *slab)
 #ifdef DEBUGGING
        assert(savestack_count == slab->opslab_refcnt-1);
 #endif
 #ifdef DEBUGGING
        assert(savestack_count == slab->opslab_refcnt-1);
 #endif
+       /* Remove the CV’s reference count. */
+       slab->opslab_refcnt--;
        return;
     }
    free:
        return;
     }
    free: