[libxml++] Another issue



Hi All,

I've got a problem just trying to get the DOM example from the online manual
to work.  The problem occurs when I try to use get_children, which returns a
NodeList object.  When that object is deleted, I get an assertion error for
MSVC - details follow:

Using:  libxml++ 2.14, Micro$oft Visual Studio 2005, using multi-threaded
CRT library (/MT)

Okay, I'm calling this function from node.cc which lives in the libxml++
DLL:

  Node::NodeList Node::get_children(const Glib::ustring& name)
  {
     xmlNode* child = impl_->children;
     if(!child)
       return NodeList();

     NodeList children;
     do
     {
        if(child->_private)
        {
          if(name.empty() || name == (const char*)child->name)
            children.push_back(reinterpret_cast<Node*>(child->_private));
        }
     }
     while((child = child->next));

     return children;
  }

Notice that it is creating and returning a NodeList, which is really just an
std::list containing Nodes.  Here is where I use it:

  {
    //Recurse through child nodes - evenually, that is
    xmlpp::Node::NodeList list = node->get_children();
  }

(Yeah, I know - I don't really use it!)  When leaving this block, I get an
exception in dbgheap.c (MSVC CRT file, it appears) at the following line of
code; note the comment for it:

  /*
   * If this ASSERT fails, a bad pointer has been passed in. It may be
   * totally bogus, or it may have been allocated from another heap.
   * The pointer MUST come from the 'local' heap.
   */
  _ASSERTE(_CrtIsValidHeapPointer(pUserData));

This seems to say the object was created on another heap (libxml++ DLL's
heap?) and being deleted by my code (using the main heap?).  It seems the
"return value optimization" has been applied, and it perhaps shouldn't have
been.  Does this make any sense?  If so, what do I do about it?  Or am I
missing something even more obvious?

Thanks!
-Bob




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]