diff options
author | Tristan Van Berkom <tristan@upstairslabs.com> | 2014-04-22 21:15:05 -0400 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2014-04-23 10:42:57 +0800 |
commit | f0dd6e11aa56addced3de33fab30529a51efaed5 (patch) | |
tree | 715c10225851e910aa0f1ca81210a7dacaddc4d1 | |
parent | 7d508fed991a35c617d0180f72200fbd7bfbd081 (diff) | |
download | libxml2-f0dd6e11aa56addced3de33fab30529a51efaed5.tar.gz |
xmlNodeSetName: Allow setting the name to a substring of the currently set name
Avoid freeing the currently set name until after having assigned the new name,
this allows one to call xmlNodeSetName (node, node->name + 1) to set the new
name of the node to a substring of the current name without introducing any
crash and without requiring an extra strdup().
-rw-r--r-- | tree.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -5096,6 +5096,7 @@ void xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { xmlDocPtr doc; xmlDictPtr dict; + const xmlChar *freeme = NULL; if (cur == NULL) return; if (name == NULL) return; @@ -5133,12 +5134,16 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { dict = NULL; if (dict != NULL) { if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) - xmlFree((xmlChar *) cur->name); + freeme = cur->name; cur->name = xmlDictLookup(dict, name, -1); } else { - if (cur->name != NULL) xmlFree((xmlChar *) cur->name); + if (cur->name != NULL) + freeme = cur->name; cur->name = xmlStrdup(name); } + + if (freeme) + xmlFree((xmlChar *) freeme); } #endif |