diff --git a/MANIFEST b/MANIFEST index 98812cb..8e80608 100644 --- a/MANIFEST +++ b/MANIFEST @@ -43,6 +43,7 @@ t/entities.t Test encoding/decoding of entities t/entities2.t Test _decode_entities() t/filter-methods.t Test ignore_tags, ignore_elements methods. t/filter.t Test HTML::Filter +t/free.t Test freeing of active parser t/handler-eof.t Test invocation of $p->eof in handlers t/handler.t Test $p->handler method t/headparser-http.t Test HTML::HeadParser diff --git a/Parser.xs b/Parser.xs index e5afea8..2db2477 100644 --- a/Parser.xs +++ b/Parser.xs @@ -377,6 +377,7 @@ parse(self, chunk) PREINIT: PSTATE* p_state = get_pstate_hv(aTHX_ self); PPCODE: + (void)sv_2mortal(SvREFCNT_inc(SvRV(self))); if (p_state->parsing) croak("Parse loop not allowed"); p_state->parsing = 1; diff --git a/t/free.t b/t/free.t new file mode 100644 index 0000000..b462d5e --- /dev/null +++ b/t/free.t @@ -0,0 +1,19 @@ +#!perl + +use strict; +use warnings; + +use Test::More tests => 1; + +use HTML::Parser; + +my $p; +$p = HTML::Parser->new( + start_h => [sub { + undef $p; + }], +); + +$p->parse(q()); + +pass 'no SEGV'; \ No newline at end of file