[gdome]reference counting



Hi developers!

I think I found a serious reference counting bug. Let me explain in the following example:

I have two documents in the memory. One was parsed from the memory the other was created by gdome_di_createDocument() and built by appending all the children. I want to traverse both trees with the same function based on gdome_n_firstChild() and gdome_n_nextSibling().

On the first document the program segfaults accessing any child node if I dereference the node returned by gdome_n_firstChild(). All document parser and gdome_doc_importNode() functions do not create GdomeNode (Gdome_xml_Node) object for all the xmlNode nodes in the document, so that the underlying xmlNode also deallocated if I dereference the node. Both traversal functions return a GdomeNode object newly created by gdome_xml_n_mkref(). In the second case the program leaks memory if I held reference to the traversed nodes, they are not even freed at gdome_doc_unref(). These nodes already has a created GdomeNode object, so they are not just allocated by gdome_xml_n_mkref().

IMHO there are several solutions all requiring great changes:
- Create an inside reference for all GdomeNode nodes for every document, freeing a document should dereference all nodes.
- Remove all reference creation from query functions
- Do not free xmlNode's freeing GdomeNode objects, only clear memory at
  freeing the document
- Create GdomeNode for every node, drop reference counting
- Use reference counting inside gdome2 (dereferencing/referencing a node decrease/increase reference of their children as well)

On the other hand the current reference counting mechanism gives
programmers lot of work to debug and fix leaks in programs and nearly doubles the code. There's nothing so easy to forget a gdome_n_unref(). Especialy reference counting for strings is rather unconfortable. It should be more like in GTK+ where the programmer not really forced to use reference counting.

Please support and use pkg-config style configuration for libxml2 and
glib-2. I will send you some patches for the build environment.


Thank you the great work,

   Daniel Kishazi



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