Skip to content

Commit 54f2533

Browse files
committed
Avoid segfault when freeing parse
RT-115034 Protect active parser from being freed URL: https://rt.cpan.org/Public/Bug/Display.html?id=115034 Author: sprout
1 parent ce42c7b commit 54f2533

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ t/entities.t Test encoding/decoding of entities
4343
t/entities2.t Test _decode_entities()
4444
t/filter-methods.t Test ignore_tags, ignore_elements methods.
4545
t/filter.t Test HTML::Filter
46+
t/free.t Test freeing of active parser
4647
t/handler-eof.t Test invocation of $p->eof in handlers
4748
t/handler.t Test $p->handler method
4849
t/headparser-http.t Test HTML::HeadParser

Parser.xs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ parse(self, chunk)
377377
PREINIT:
378378
PSTATE* p_state = get_pstate_hv(aTHX_ self);
379379
PPCODE:
380+
(void)sv_2mortal(SvREFCNT_inc(SvRV(self)));
380381
if (p_state->parsing)
381382
croak("Parse loop not allowed");
382383
p_state->parsing = 1;

t/free.t

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!perl -w
2+
3+
use Test::More tests => 1;
4+
5+
use HTML::Parser;
6+
$p = new HTML::Parser(
7+
start_h => [sub {
8+
undef $p;
9+
}],
10+
);
11+
12+
$p->parse(q(<foo>));
13+
14+
pass;

0 commit comments

Comments
 (0)