Need Help: LibXML + LWP::Simple Is Making Perl Crash

Need Help: LibXML + LWP::Simple Is Making Perl Crash

am 26.12.2007 05:24:54 von Mott.Jeff

I've been getting a very weird bug. No error message. perl simply
crashes. With lots of trial and error, I've narrowed down the parts
that cause the crash. Below is some very simple code that -- on my
WinXP comp with ActivePerl 5.8.8 -- will crash reliably.



use strict;
use warnings FATAL => 'all';

use XML::LibXML;
use LWP::Simple;


# The XML structure...
#
#
# Hello, World!
#

#

my $rootNode = XML::LibXML::Element->new('myroot');

my $someNode = XML::LibXML::Element->new('somenode');
$rootNode->appendChild($someNode);

my $someDeeperNode = XML::LibXML::Element->new('somedeepernode');
$someDeeperNode->appendText('Hello, World!');
$someNode->appendChild($someDeeperNode);



my @someNodes = $rootNode->getElementsByTagName('somenode');
foreach my $someNode (@someNodes)
{
# If this line is commented, then all is good.
# But if it's left in... crash.
my $theText = $someNode->findvalue('somedeepernode');

# This line -- a different way to accomplish
# the same thing -- would crash too.
# my $theText = $someNode->getElementsByTagName('somedeepernode')-
>get_node(1)->nodeValue;
}



# Or if this line is commented, then all is good also. But because
I've had
# other weirdness with getting text from XML nodes, I'm leaning toward
LibXML
# being the culprit.
my $x = get('http://www.perl.com');



print q`If you're reading this, then it worked!`;

Re: Need Help: LibXML + LWP::Simple Is Making Perl Crash

am 26.12.2007 06:30:15 von Ivan Novick

On Dec 25, 8:24 pm, "Jeff.M" wrote:
> I've been getting a very weird bug. No error message. perl simply
> crashes. With lots of trial and error, I've narrowed down the parts
> that cause the crash. Below is some very simple code that -- on my
> WinXP comp with ActivePerl 5.8.8 -- will crash reliably.
>
> use strict;
> use warnings FATAL => 'all';
>
> use XML::LibXML;
> use LWP::Simple;
-- snip --

There are clearly issues/bugs with XML::LibXML.

I have run your program via valgrind memory profiler on a debian
system with perl 5.8 and there are numerous illegal memory usages
coming from the LibXML library.

Here is an example:
==2253== Invalid read of size 4
==2253== at 0x48338E6: domXPathFind (in /usr/lib/perl5/auto/XML/
LibXML/LibXML.so)
==2253== by 0x4814705: XS_XML__LibXML__Node__find (in /usr/lib/
perl5/auto/XML/LibXML/LibXML.so)
==2253== by 0x80BDAC0: Perl_pp_entersub (in /usr/bin/perl)
==2253== by 0x80BC398: Perl_runops_standard (in /usr/bin/perl)
==2253== by 0x8063BFC: perl_run (in /usr/bin/perl)
==2253== by 0x805FFD0: main (in /usr/bin/perl)
==2253== Address 0x476C534 is 20 bytes inside a block of size 88
free'd
==2253== at 0x401CFA5: free (vg_replace_malloc.c:233)
==2253== by 0x44093D6: xmlFreeDoc (in /usr/lib/libxml2.so.2.6.27)
==2253== by 0x483388D: domXPathFind (in /usr/lib/perl5/auto/XML/
LibXML/LibXML.so)
==2253== by 0x483393A: domXPathSelect (in /usr/lib/perl5/auto/XML/
LibXML/LibXML.so)
==2253== by 0x48141D6: XS_XML__LibXML__Node__findnodes (in /usr/lib/
perl5/auto/XML/LibXML/LibXML.so)
==2253== by 0x80BDAC0: Perl_pp_entersub (in /usr/bin/perl)
==2253== by 0x80BC398: Perl_runops_standard (in /usr/bin/perl)
==2253== by 0x8063BFC: perl_run (in /usr/bin/perl)
==2253== by 0x805FFD0: main (in /usr/bin/perl)

I would recommend using another module for XML handling and submitting
a bug to the maintainer of this package.

Regards,
Ivan Novick
http://www.0x4849.net

Re: Need Help: LibXML + LWP::Simple Is Making Perl Crash

am 31.12.2007 09:57:18 von Todd Wade

On Dec 26, 12:30=A0am, Ivan Novick wrote:
> On Dec 25, 8:24 pm, "Jeff.M" wrote:
> > I've been getting a very weird bug. No error message. perl simply
> > crashes.
>
> There are clearly issues/bugs with XML::LibXML.
>
> I have run your program via valgrind memory profiler on a debian
> system with perl 5.8 and there are numerous illegal memory usages
> coming from the LibXML library.
> ...
> I would recommend using another module for XML handling and submitting
> a bug to the maintainer of this package.

Wow. XML::LibXML is broken? Bummer.

http://groups.google.com/group/comp.lang.perl.misc/tree/brow se_frm/thread/fa=
29dd5a61b99bbd/e91364d8f1816315

Re: Need Help: LibXML + LWP::Simple Is Making Perl Crash

am 01.01.2008 22:02:09 von pajas

Hi Ivan, Jeff ,Todd,

XML::LibXML has a maintainer (me), so if you see something like this,
you better report it via rt.cpan.org than cry on usnet forums. Anyway,
I can confirm this problem exists with version 1.65 and earlier, but
in the SVN, it has been already fixed (due to somebody else's
report).

And by the way, the problem with the example code is that you do not
create a document node first. Make it

my $doc =3D XML::LibXML::Document->new;
$doc->createElement(...)

and things will start to work with 1.65 too.

Please wait for the next release or refer to
http://search.cpan.org/src/PAJAS/XML-LibXML-1.65/README
on how to install from SVN (the README assumes POSIX-like environment,
I fear it may be a bit trickier on windows).

-- Petr

Todd Wade wrote:
> On Dec 26, 12:30ï¿=BDam, Ivan Novick wrote:
> > On Dec 25, 8:24 pm, "Jeff.M" wrote:
> > > I've been getting a very weird bug. No error message. perl simply
> > > crashes.
> >
> > There are clearly issues/bugs with XML::LibXML.
> >
> > I have run your program via valgrind memory profiler on a debian
> > system with perl 5.8 and there are numerous illegal memory usages
> > coming from the LibXML library.
> > ...
> > I would recommend using another module for XML handling and submitting
> > a bug to the maintainer of this package.
>
> Wow. XML::LibXML is broken? Bummer.
>
> http://groups.google.com/group/comp.lang.perl.misc/tree/brow se_frm/thread/=
fa29dd5a61b99bbd/e91364d8f1816315