reference counting again

Chaoron <[email protected]>
Newsgroups gmane.comp.gnome.gdome
Message-ID <[email protected]>
Hi!

I've got another code snippet. I've tried to only unref the first 
child, but it's not helped. Works the same with gdome_n_lastChild() 
instead. I could not find any error in my code. No idea about the 
solution. Compiled with gcc (2.95.2) on Debian Potato with gdome-0.7.2, 
libxml-2.4.22, glib-2.03. See the attached gdome-test2.c file.

Daniel Kishazi
gdome-test2.c (text/x-c, 1.8 KB)
#include <gdome.h>
#include <gdome-treegc.h>

static GdomeDocument *convert_node(GdomeNode *node);

static gchar *treetext = "<?xml version=\"1.0\"?>\n" \
                         "<root><child_1/><child_2/><child_3/></root>\n";

int
main(int argc, char *argv[])
{
  GdomeDOMImplementation *imp;
  GdomeDocument *doc, *doc2;
  GdomeNode *root;
  GdomeException exc;
  
  
  imp = gdome_di_mkref();
  doc = gdome_di_createDocFromMemory(imp, treetext, GDOME_LOAD_PARSING, &exc);
  gdome_di_unref(imp, &exc);
  
  root = (GdomeNode *) gdome_doc_documentElement(doc, &exc);
  
  doc2 = convert_node(root); // Leaks two GdomeNode objects
  
/* ... */
  
  gdome_n_unref(root, &exc);
  gdome_doc_unref(doc2, &exc);
  gdome_doc_unref(doc, &exc);
  
  return 0;
}


GdomeDocument *
convert_node(GdomeNode *node)
{
  GdomeDocument *self;
  GdomeNode *newnode, *root, *tmpnode;
  GdomeDOMImplementation *imp;
  GdomeDOMString *domname;
  GdomeException exc;
  
  g_return_val_if_fail(node != NULL, NULL);
  

  imp = gdome_di_mkref();
  domname = gdome_n_nodeName(node, &exc);
  self = gdome_di_createDocument(imp, NULL, domname, NULL, &exc);
  gdome_str_unref(domname);
  gdome_di_unref(imp, &exc);
  
  newnode = gdome_doc_importNode(self, node, TRUE, &exc);
  root = (GdomeNode *) gdome_doc_documentElement(self, &exc);
  
  while ((tmpnode = gdome_n_firstChild(newnode, &exc)) != NULL)
    {
      g_print("lives: %d\n", gdome_treegc_livenodes(tmpnode));
      gdome_n_appendChild(root, tmpnode, &exc);
      gdome_n_unref(tmpnode, &exc);
// FIXME: dereferencing segfaults, looks decreases reference count of siblings
//      gdome_n_unref(tmpnode, &exc);
      g_print("lives left: %d\n\n", gdome_treegc_livenodes(tmpnode));
    }
  
  gdome_n_unref(root, &exc);
  gdome_n_unref(newnode, &exc);
  
  return self;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.