[gdome]Segfault with createElement/ownerDocument



Christopher Gutteridge pointed out to me a problem with XML::GDOME which 
also occurs with the C library.  If you call createElement on a doc, 
free the doc, free the result of calling ownerDocument on the created 
element, then a segfault occurs.  I think this happens because 
createElement doesn't increase the livenodes on the document tree, so the 
document gets freed before ownerDocument is called.

Here is the C code that causes a segfault.

#include <gdome.h>
int main (int argc, char **argv) {
        GdomeDOMImplementation *domimpl = gdome_di_mkref ();
        GdomeDOMString *name = gdome_str_mkref ("demo");
        GdomeException exc = 0;
        GdomeDocument *doc = gdome_di_createDocument(domimpl, NULL, name, NULL, &exc);
        GdomeElement *demo = gdome_doc_documentElement (doc, &exc);
        GdomeDOMString *name2 = gdome_str_mkref ("annie");
        GdomeElement *annie = gdome_doc_createElement(doc,name2, &exc);
        gdome_doc_unref (doc, &exc);  /* DOC     unref */
        gdome_el_unref(demo, &exc);   /* Element unref */
        GdomeDocument *owner = gdome_el_ownerDocument(annie, &exc);

	/* segfault occurs here */
        gdome_doc_unref(owner, &exc);

        gdome_el_unref(annie, &exc);
        gdome_di_unref (domimpl, &exc);
        return 0;
}

Cheers,
TJ




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