| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Scalar::Util; |
| 5 |
use XML::LibXML; |
| 6 |
|
| 7 |
if (defined (&Scalar::Util::weaken)) |
| 8 |
{ |
| 9 |
plan tests => 1; |
| 10 |
} |
| 11 |
else |
| 12 |
{ |
| 13 |
plan skip_all => 'Need Scalar::Util::weaken'; |
| 14 |
} |
| 15 |
|
| 16 |
my $is_destroyed; |
| 17 |
BEGIN |
| 18 |
{ |
| 19 |
no warnings 'once', 'redefine'; |
| 20 |
my $old = \&XML::LibXML::Element::DESTROY; |
| 21 |
*XML::LibXML::Element::DESTROY = sub |
| 22 |
{ |
| 23 |
$is_destroyed++; |
| 24 |
$old->(@_); |
| 25 |
}; |
| 26 |
} |
| 27 |
|
| 28 |
# Create element... |
| 29 |
my $root = XML::LibXML->load_xml( IO => \*DATA )->documentElement; |
| 30 |
|
| 31 |
# allow %hash to go out of scope quickly. |
| 32 |
{ |
| 33 |
my %hash = %$root; |
| 34 |
# assignment to ensure block is not optimized away |
| 35 |
$hash{foo} = 'phooey'; |
| 36 |
} |
| 37 |
|
| 38 |
# Destroy element... |
| 39 |
undef($root); |
| 40 |
|
| 41 |
# Touch the fieldhash... |
| 42 |
my %other = %{ XML::LibXML->load_xml( string => '<foo/>' )->documentElement }; |
| 43 |
|
| 44 |
# TEST |
| 45 |
ok($is_destroyed, "does not leak memory"); |
| 46 |
|
| 47 |
__DATA__ |
| 48 |
<root attr1="foo" xmlns:x="http://localhost/" x:attr2="bar" /> |