LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-20-2004, 05:47 AM   #1
isl01jbe
LQ Newbie
 
Registered: May 2004
Distribution: Slackware
Posts: 11

Rep: Reputation: 0
libxml++: segmentation fault when exiting program.


I'm trying to implement a simple xml-reader in c++ using libxml++. So far i've manged to open the xml-document, print the relevant parts and then exit. the problem is that i get a segmentation fault when exiting.

Code:
int main() 
 {
   Glib::ustring file_name = "test.xml";
    xmlpp::DomParser test(file_name);
    xmlpp::Document* test_xml = test.get_document();
    xmlpp::Element*  root_node = test_xml->get_root_node();
    xmlpp::Element::NodeList children = root_node->get_children(Glib::ustring("item"));
    xmlpp::Element::NodeList::iterator i;
    i = children.begin();
    while (i != children.end())
      {
              xmlpp::Element::NodeList item_list = (*i)->get_children(Glib::ustring("title"));
              xmlpp::Element::NodeList::iterator g;
              g = item_list.begin();
              while (g!=item_list.end())
                {  
                      if (xmlpp::Element((*g)->cobj()).has_child_text())
                        {
                          xmlpp::Element test((*g)->cobj());
                          cout << (test.get_child_text())->get_content() << endl;
                         }                    
                  g++;
                }
        i++;
      }
  }
Is there something missing? Do i have to close the specific document in some way? gdb outputs:

Code:
#0  0x40243eaf in _int_free () from /lib/libc.so.6
#1  0x40242cdf in free () from /lib/libc.so.6
#2  0x4017cd75 in operator delete (ptr=0x433318)
    at ../../../../gcc-3.3.3/libstdc++-v3/libsupc++/del_op.cc:39
#3  0x400ee2cf in xmlpp::NonCopyable::~NonCopyable ()
   from /usr/lib/libxml++-2.6.so.1
#4  0x400ed588 in (anonymous namespace)::on_libxml_destruct ()
   from /usr/lib/libxml++-2.6.so.1
#5  0x4037d200 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#6  0x4037d0c1 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#7  0x4037d0c1 in xmlFreeNodeList () from /usr/lib/./libxml2.so.2
#8  0x4037ad2d in xmlFreeDoc () from /usr/lib/./libxml2.so.2
#9  0x400ed86b in xmlpp::Document::~Document () from /usr/lib/libxml++-2.6.so.1
#10 0x0804901b in main () at test.cpp:36
so obviously there is something wrong with how the destructor works?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why segmentation fault in this program? asahlot Programming 13 10-17-2005 12:47 PM
Wine wont start program, segmentation fault, artsdsp nontoxic Linux - Software 3 03-21-2005 06:27 AM
Program received signal SIGSEGV, Segmentation fault ims_mca Linux - Distributions 0 03-09-2005 04:16 AM
Why do i get segmentation fault upon exiting main() J-Ral Programming 5 05-28-2004 04:27 AM
"segmentation fault" when run a simple c program acer_peri Programming 11 05-28-2004 04:14 AM


All times are GMT -5. The time now is 01:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration