File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,7 @@ PHP_METHOD(DOMElement, getAttribute)
205
205
dom_object * intern ;
206
206
xmlNodePtr attr ;
207
207
size_t name_len ;
208
+ bool should_free ;
208
209
209
210
id = ZEND_THIS ;
210
211
if (zend_parse_parameters (ZEND_NUM_ARGS (), "s" , & name , & name_len ) == FAILURE ) {
@@ -218,20 +219,25 @@ PHP_METHOD(DOMElement, getAttribute)
218
219
switch (attr -> type ) {
219
220
case XML_ATTRIBUTE_NODE :
220
221
value = xmlNodeListGetString (attr -> doc , attr -> children , 1 );
222
+ should_free = true;
221
223
break ;
222
224
case XML_NAMESPACE_DECL :
223
- value = xmlStrdup (((xmlNsPtr )attr )-> href );
225
+ value = (xmlChar * ) ((xmlNsPtr )attr )-> href ;
226
+ should_free = false;
224
227
break ;
225
228
default :
226
- value = xmlStrdup (((xmlAttributePtr )attr )-> defaultValue );
229
+ value = (xmlChar * ) ((xmlAttributePtr )attr )-> defaultValue ;
230
+ should_free = false;
227
231
}
228
232
}
229
233
230
234
if (value == NULL ) {
231
235
RETURN_EMPTY_STRING ();
232
236
} else {
233
237
RETVAL_STRING ((char * )value );
234
- xmlFree (value );
238
+ if (should_free ) {
239
+ xmlFree (value );
240
+ }
235
241
}
236
242
}
237
243
/* }}} end dom_element_get_attribute */
You can’t perform that action at this time.
0 commit comments