Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

close issue #71; SV leaks in VM frames

  • Loading branch information...
commit 9512d5df87a96df155b1815c0d851ac3d62a702e 1 parent 26434e1
@gfx gfx authored
View
1  lib/Text/Xslate/PP.pm
@@ -572,6 +572,7 @@ sub tx_execute {
local $st->{sb};
local $st->{output} = '';
$st->{code}->[0]->{ exec_code }->( $st );
+ @{$st->{frame}->[-1]} = Text::Xslate::PP::TXframe_START_LVAR - 1;
return $st->{output};
}
View
4 src/Text-Xslate.xs
@@ -329,7 +329,8 @@ tx_push_frame(pTHX_ tx_state_t* const st) {
static void
tx_pop_frame(pTHX_ tx_state_t* const st, bool const replace_output) {
AV* const top = TX_frame_at(st, st->current_frame);
- SV** const ary = AvARRAY(top);
+
+ av_fill(top, TXframe_START_LVAR - 1);
assert( st->current_frame >= 0 );
if (--st->current_frame >= 0) {
@@ -339,6 +340,7 @@ tx_pop_frame(pTHX_ tx_state_t* const st, bool const replace_output) {
}
if(replace_output) {
+ SV** const ary = AvARRAY(top);
SV* const tmp = ary[TXframe_OUTPUT];
ary[TXframe_OUTPUT] = st->output;
st->output = tmp;
View
42 t/900_bugs/030_issue71.t
@@ -0,0 +1,42 @@
+#!perl
+# https://github.com/xslate/p5-Text-Xslate/issues/71
+use strict;
+use warnings;
+use Text::Xslate;
+use Test::More;
+
+my $tx = Text::Xslate->new('syntax' => 'TTerse',);
+my $CLEANUP_OK;
+
+{
+ package MyHandle;
+ sub new { bless {}, shift }
+ sub DESTROY {
+ $CLEANUP_OK++;
+ }
+}
+
+{
+ my $dbh = MyHandle->new();
+ my @book = (
+ {title => "foo", dbh => $dbh},
+ {title => "bar", dbh => $dbh},
+ );
+ my $template = q{
+<h1>[% title %]</h1>
+<ul>
+[% FOREACH book IN books %]
+[% SET test = book %]
+ <li>[% book.title %]</li>
+[% END %]
+</ul>
+};
+ my $body = $tx->render_string($template, {
+ books => \@book,
+ });
+ isnt $body, '', 'render_string() succeeded';
+}
+
+ok($CLEANUP_OK, '$dbh is released');
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.