diff --git a/gentest.py b/gentest.py index 79025f83..179c872b 100755 --- a/gentest.py +++ b/gentest.py @@ -224,7 +224,7 @@ extra_post_call = { "xmlAddPrevSibling": "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }", "xmlDocSetRootElement": - "if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; }", + "if (ret_val == NULL) { xmlFreeNode(root) ; root = NULL ; }", "xmlReplaceNode": """if (cur != NULL) { xmlUnlinkNode(cur); diff --git a/testapi.c b/testapi.c index 35c74fa6..9b438f1f 100644 --- a/testapi.c +++ b/testapi.c @@ -19789,7 +19789,7 @@ test_xmlDocSetRootElement(void) { root = gen_xmlNodePtr_in(n_root, 1); ret_val = xmlDocSetRootElement(doc, root); - if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; } + if (ret_val == NULL) { xmlFreeNode(root) ; root = NULL ; } desret_xmlNodePtr(ret_val); call_tests++; des_xmlDocPtr(n_doc, doc, 0); diff --git a/tree.c b/tree.c index 5fc36f98..be8485a5 100644 --- a/tree.c +++ b/tree.c @@ -5060,7 +5060,7 @@ xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { xmlNodePtr old = NULL; if (doc == NULL) return(NULL); - if ((root == NULL) || (root->type == XML_NAMESPACE_DECL)) + if ((root == NULL) || (root->type != XML_ELEMENT_NODE)) return(NULL); xmlUnlinkNode(root); xmlSetTreeDoc(root, doc);