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

Discussion in 'Perl Misc' started by Jeff.M, Dec 26, 2007.

  1. Jeff.M

    Jeff.M Guest

    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!`;
    Jeff.M, Dec 26, 2007
    #1
    1. Advertising

  2. Jeff.M

    Ivan Novick Guest

    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
    Ivan Novick, Dec 26, 2007
    #2
    1. Advertising

  3. Jeff.M

    Todd Wade Guest

    On Dec 26, 12:30 am, 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..._frm/thread/fa29dd5a61b99bbd/e91364d8f1816315
    Todd Wade, Dec 31, 2007
    #3
  4. Jeff.M

    Guest

    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

    Todd Wade wrote:
    > On Dec 26, 12:30�am, 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..._frm/thread/fa29dd5a61b99bbd/e91364d8f1816315
    , Jan 1, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Gregory
    Replies:
    1
    Views:
    493
  2. Olav
    Replies:
    3
    Views:
    4,203
  3. Karra
    Replies:
    2
    Views:
    754
    Octavian Rasnita
    Dec 29, 2010
  4. Leif Wessman

    Error when using XML::Simple with XML::LibXML

    Leif Wessman, Jun 18, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    116
    Leif Wessman
    Jun 18, 2004
  5. Replies:
    0
    Views:
    79
Loading...

Share This Page