1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Avoid string duplication if possible in SimpleXMLElement::addAttribute() (#15606)

This commit is contained in:
Niels Dossche
2024-08-27 23:07:20 +02:00
committed by GitHub
parent 067eb8c0d7
commit 9b73d591c6

View File

@@ -1753,7 +1753,8 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
}
localname = xmlSplitQName2((xmlChar *)qname, &prefix);
if (localname == NULL) {
bool free_localname = localname != NULL;
if (!free_localname) {
if (nsuri_len > 0) {
if (prefix != NULL) {
xmlFree(prefix);
@@ -1761,17 +1762,13 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
php_error_docref(NULL, E_WARNING, "Attribute requires prefix for namespace");
return;
}
localname = xmlStrdup((xmlChar *)qname);
localname = (xmlChar *) qname;
}
attrp = xmlHasNsProp(node, localname, (xmlChar *)nsuri);
if (attrp != NULL && attrp->type != XML_ATTRIBUTE_DECL) {
xmlFree(localname);
if (prefix != NULL) {
xmlFree(prefix);
}
php_error_docref(NULL, E_WARNING, "Attribute already exists");
return;
goto out;
}
if (nsuri != NULL) {
@@ -1783,7 +1780,10 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
attrp = xmlNewNsProp(node, nsptr, localname, (xmlChar *)value);
xmlFree(localname);
out:
if (free_localname) {
xmlFree(localname);
}
if (prefix != NULL) {
xmlFree(prefix);
}