| 1 |
|
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Scalar::Util qw(blessed); |
| 5 |
|
| 6 |
=head1 DESCRIPTION |
| 7 |
|
| 8 |
Double free on RHEL-5-x86_64. |
| 9 |
|
| 10 |
See L<https://rt.cpan.org/Ticket/Display.html?id=83779>. |
| 11 |
|
| 12 |
=cut |
| 13 |
|
| 14 |
use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace }; |
| 15 |
use Test::More HAS_LEAKTRACE ? (tests => 6) : (skip_all => 'Test::LeakTrace is required.'); |
| 16 |
use Test::LeakTrace; |
| 17 |
use XML::LibXML::Reader; |
| 18 |
|
| 19 |
my $xml = <<'EOF'; |
| 20 |
<html> |
| 21 |
<head> |
| 22 |
<title>David vs. Goliath - Part I</title> |
| 23 |
</head> |
| 24 |
<body> |
| 25 |
</body> |
| 26 |
</html> |
| 27 |
EOF |
| 28 |
|
| 29 |
my $xml_decl = <<'EOF'; |
| 30 |
<?xml version="1.0"?> |
| 31 |
EOF |
| 32 |
|
| 33 |
{ |
| 34 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 35 |
my @nodes; |
| 36 |
while ($r->read) { |
| 37 |
push @nodes, $r->name; |
| 38 |
} |
| 39 |
# TEST |
| 40 |
is( |
| 41 |
join(',', @nodes), |
| 42 |
'html,#text,head,#text,title,#text,title,#text,head,#text,body,#text,body,#text,html', |
| 43 |
'Check reader' |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
{ |
| 48 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 49 |
while ($r->read) { |
| 50 |
$r->preserveNode(); |
| 51 |
} |
| 52 |
# TEST |
| 53 |
is( |
| 54 |
$r->document->toString(), |
| 55 |
$xml_decl . $xml, |
| 56 |
'Check reader with using preserveNode' |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
{ |
| 61 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 62 |
my $copy; |
| 63 |
while ($r->read) { |
| 64 |
$copy = $r->copyCurrentNode() if $r->name eq 'body'; |
| 65 |
} |
| 66 |
# TEST |
| 67 |
is( |
| 68 |
$copy->toString(), |
| 69 |
'<body/>', |
| 70 |
'Check reader with using copyCurrentNode' |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
# TEST |
| 75 |
no_leaks_ok { |
| 76 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 77 |
while ($r->read) { |
| 78 |
# nothing |
| 79 |
} |
| 80 |
} 'Check reader, without leaks'; |
| 81 |
|
| 82 |
# TEST |
| 83 |
no_leaks_ok { |
| 84 |
my $node; |
| 85 |
{ |
| 86 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 87 |
while ($r->read) { |
| 88 |
$node ||= $r->preserveNode(); |
| 89 |
} |
| 90 |
my $doc = $r->document(); |
| 91 |
} |
| 92 |
} 'Check reader with using preserveNode, without leaks'; |
| 93 |
|
| 94 |
# TEST |
| 95 |
no_leaks_ok { |
| 96 |
my $r = XML::LibXML::Reader->new(string => $xml); |
| 97 |
while ($r->read) { |
| 98 |
my $copy = $r->copyCurrentNode(); |
| 99 |
} |
| 100 |
} 'Check reader with using copyCurrentNode, without leaks'; |