Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

5 views
Skip to first unread message

Jeff.M

unread,
Dec 25, 2007, 11:24:54 PM12/25/07
to
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...
# <myroot>
# <somenode>
# <somedeepernode>Hello, World!</somedeepernode>
# </somenode>
# </myroot>
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!`;

Ivan Novick

unread,
Dec 26, 2007, 12:30:15 AM12/26/07
to
On Dec 25, 8:24 pm, "Jeff.M" <Mott.J...@gmail.com> 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

Todd Wade

unread,
Dec 31, 2007, 3:57:18 AM12/31/07
to pa...@matfyz.cz
On Dec 26, 12:30 am, Ivan Novick <i...@0x4849.net> wrote:
> On Dec 25, 8:24 pm, "Jeff.M" <Mott.J...@gmail.com> 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/browse_frm/thread/fa29dd5a61b99bbd/e91364d8f1816315

pa...@matfyz.cz

unread,
Jan 1, 2008, 4:02:09 PM1/1/08
to
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 = 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

0 new messages