Skip to content

Commit

Permalink
Change again where the freeing happens
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Mar 25, 2014
1 parent 45e1523 commit c791c28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changes
=======

{{$NEXT}}
- Fix rt#94173 by freeing the handler at finish time
- Use Minilla for packaging the dist

0.00006 - 20 Oct 2012
- No code change
- Upgrade to Module::Install 1.06
(see http://weblog.bulknews.net/post/33907905561/do-not-ship-modules-with-module-install-1-04)

0.00005 - 28 Feb 2011
- Remove auto_include, and thus remove Test::More (rt #75361)

Expand Down
37 changes: 25 additions & 12 deletions lib/XML/LibXML/SAX/ChunkParser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,48 @@ use base qw(XML::SAX::Base);
use XML::LibXML;
use Carp qw(croak);

our $VERSION = '0.00005';
our $VERSION = '0.00006';

sub DESTROY {
my $self = shift;
$self->clean_parser;
}

sub clean_parser {
my $self = shift;

my $option = $self->{ParserOptions};
my $option = delete $self->{ParserOptions};
if (! $option) {
return;
}
my $parser = $option->{LibParser};
my $parser = delete $option->{LibParser};
if (! $parser) {
return;
}
# break a possible circular reference
$parser->set_handler( undef );
}

sub parse_chunk {
my ($self, $chunk) = @_;
sub get_parser {
my $self = shift;
my $options = $self->{ParserOptions};
if (! $options) {
$options = {};
$options->{LibParser} = XML::LibXML->new;
$self->{ParserOptions} = $options;
}

my $parser = $options->{LibParser};
$parser->set_handler($self);
if (! $parser) {
$parser = $options->{LibParser} = XML::LibXML->new;
$parser->set_handler($self);
}
return $parser;
}

sub parse_chunk {
my ($self, $chunk) = @_;

my $parser = $self->get_parser();
eval {
$parser->parse_chunk( $chunk );
};
Expand All @@ -47,14 +61,13 @@ sub parse_chunk {

sub finish {
my $self = shift;
my $options = $self->{ParserOptions};
if (! $options) {
$options->{LibParser} = XML::LibXML->new;
}
my $parser = $options->{LibParser};

my $parser = $self->get_parser();
if ($parser) {
$parser->parse_chunk("", 1);
}

$self->clean_parser();
}

1;
Expand Down

0 comments on commit c791c28

Please sign in to comment.