in reply to Re^3: XML::LibXML memory leak
in thread XML::LibXML memory leak

Thank you. Very much...

I get it, but - but would like to clarify. I give the node to a new document outside my loop, like this:

my $foster_home = XML::LibXML::Document->new("1.0", "UTF-8"); # Register the namespaces: $cve_xc->registerNs( def => 'http://scap.nist.gov/schema/feed/vulnerab +ility/2.0' ); $cve_xc->registerNs( vuln => 'http://scap.nist.gov/schema/vulnerabilit +y/0.4' ); $cve_xc->registerNs( cvss => 'http://scap.nist.gov/schema/cvss-v2/0.2' + ); # Find the appropriate CVE entry in the data source: for my $entry ( $cve_xc->findnodes( "/def:nvd/def:entry[\@id = '$cve_i +d']" )) { if ( my ( $metrics ) = $cve_xc->findnodes( 'vuln:cvss/cvss:base_me +trics', $entry )) { ($av) = $cve_xc->find('cvss:access-vector', $metrics); ($ac) = $cve_xc->find('cvss:access-complexity', $metrics); ($au) = $cve_xc->find('cvss:authentication', $metrics); ($ci) = $cve_xc->find('cvss:confidentiality-impact', $metrics) +; ($ii) = $cve_xc->find('cvss:integrity-impact', $metrics); ($ai) = $cve_xc->find('cvss:availability-impact', $metrics); } else { $av = ""; $ac = ""; $au = ""; $ci = ""; $ii = ""; $ai = ""; } } $av->setOwnerDocument($foster_home); $ac->setOwnerDocument($foster_home); $au->setOwnerDocument($foster_home); $ci->setOwnerDocument($foster_home); $ii->setOwnerDocument($foster_home); $ai->setOwnerDocument($foster_home);

But I'm a little confused as where to go from here: my $doc = $node->ownerDocument;

I'm also stymied at the moment as I'm getting "Can't locate object method "setOwnerDocument" via package "XML::LibXML::NodeList" at..."

I've reinstalled XML::LIbXML via CPAN, have "Node.pod" in /Library/Perl/5.10.0/darwin-thread-multi-2level/XML/LibXML, but only NodeList.pm...

Replies are listed 'Best First'.
Re^5: XML::LibXML memory leak
by ikegami (Patriarch) on Dec 08, 2010 at 19:37 UTC

    But I'm a little confused as where to go from here: my $doc = $node->ownerDocument;

    { my $doc = $node->ownerDocument; say "owner=", $doc; if ($doc) { say $_->nodeName for $doc->findnodes("//*"); } }

    was just to demonstrate the issue. It shouldn't be part of your code.

    I'm also stymied at the moment as I'm getting "Can't locate object method "setOwnerDocument" via package "XML::LibXML::NodeList" at..."

    Nodes have owner documents, not result sets. Change the owner of the nodes in the result set.

    Can't you just extract the data you need from the nodes instead of keeping the nodes themselves?

      Yes, absolutely! All I need is the data...

      That's what I thought that I was doing with:

      $av = $cve_xc->find('cvss:access-vector', $metrics);

        Ah oops, I thought you were using ->findnodes.

        The only possible things that could match are: 0 elements, 1 element, or multiple elements. I never use ->find, so I don't know what it returns in each of those circumstances, and whether any of those are connected to the document.