mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Avoid allocations in DOMElement::getAttribute()
This commit is contained in:
parent
9880c336be
commit
f04e5059bb
1 changed files with 9 additions and 3 deletions
|
@ -205,6 +205,7 @@ PHP_METHOD(DOMElement, getAttribute)
|
|||
dom_object *intern;
|
||||
xmlNodePtr attr;
|
||||
size_t name_len;
|
||||
bool should_free;
|
||||
|
||||
id = ZEND_THIS;
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
|
||||
|
@ -218,12 +219,15 @@ PHP_METHOD(DOMElement, getAttribute)
|
|||
switch (attr->type) {
|
||||
case XML_ATTRIBUTE_NODE:
|
||||
value = xmlNodeListGetString(attr->doc, attr->children, 1);
|
||||
should_free = true;
|
||||
break;
|
||||
case XML_NAMESPACE_DECL:
|
||||
value = xmlStrdup(((xmlNsPtr)attr)->href);
|
||||
value = (xmlChar *) ((xmlNsPtr)attr)->href;
|
||||
should_free = false;
|
||||
break;
|
||||
default:
|
||||
value = xmlStrdup(((xmlAttributePtr)attr)->defaultValue);
|
||||
value = (xmlChar *) ((xmlAttributePtr)attr)->defaultValue;
|
||||
should_free = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,7 +235,9 @@ PHP_METHOD(DOMElement, getAttribute)
|
|||
RETURN_EMPTY_STRING();
|
||||
} else {
|
||||
RETVAL_STRING((char *)value);
|
||||
xmlFree(value);
|
||||
if (should_free) {
|
||||
xmlFree(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} end dom_element_get_attribute */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue