diff -ur libxml2-2.4.11.old/tree.c libxml2-2.4.11/tree.c --- libxml2-2.4.11.old/tree.c Mon Nov 26 14:35:05 2001 +++ libxml2-2.4.11/tree.c Thu Jan 10 15:41:43 2002 @@ -2777,8 +2777,18 @@ xmlBufferLength(node->content)); #endif } - if (parent != NULL) - xmlAddChild(parent, ret); + if (parent != NULL) { + xmlNodePtr last = parent->last; + xmlNodePtr child = xmlAddChild(parent, ret); + if (last == child) { + /* + * When copying consecutive text nodes, xmlAddChild will + * free 'ret' and return parent->last. In that case return + * parent->last as well... + */ + return last; + } + } if (!recursive) return(ret); if (node->nsDef != NULL) @@ -2849,8 +2859,17 @@ } else { q = (xmlNodePtr) doc->intSubset; } - } else + } else { q = xmlStaticCopyNode(node, doc, parent, 1); + if (p == q) { + /* + * The node 'node' was a text node merged into the + * previous node 'p' + */ + node = node->next; + continue; + } + } if (ret == NULL) { q->prev = NULL; ret = p = q;