cvs: php4(PHP_4_3) /ext/domxml php_domxml.c
| From: | Christian Stocker | Date: | Wed, 09 Apr 2003 07:33:20 +0000 |
| Subject: | cvs: php4(PHP_4_3) /ext/domxml php_domxml.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20190@lists.php.net to get a copy of this message | ||
chregu Wed Apr 9 03:33:20 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4/ext/domxml php_domxml.c
Log:
fixed some memleaks when using attribute nodes (Rob Richards)
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.218.2.15 php4/ext/domxml/php_domxml.c:1.218.2.16
--- php4/ext/domxml/php_domxml.c:1.218.2.15 Tue Apr 8 15:30:46 2003
+++ php4/ext/domxml/php_domxml.c Wed Apr 9 03:33:19 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.218.2.15 2003/04/08 19:30:46 chregu Exp $ */
+/* $Id: php_domxml.c,v 1.218.2.16 2003/04/09 07:33:19 chregu Exp $ */
/* TODO
* - Support Notation Nodes
@@ -749,6 +749,8 @@
{
xmlNodePtr node = (xmlNodePtr) rsrc->ptr;
if (node->parent == NULL) {
+ /* Attribute Nodes contain accessible children */
+ node_list_wrapper_dtor(node->children, 0);
node_wrapper_dtor(node);
xmlFreeProp((xmlAttrPtr) node);
} else {
@@ -1789,12 +1791,42 @@
{
zval *id;
xmlAttrPtr attrp;
+ xmlChar *content;
DOMXML_GET_THIS_OBJ(attrp, id, le_domxmlattrp);
DOMXML_NO_ARGS();
- RETURN_STRING((char *) xmlNodeGetContent((xmlNodePtr) attrp), 1);
+ /* RETURN_STRING((char *) xmlNodeGetContent((xmlNodePtr) attrp), 1); */
+ if (content = xmlNodeGetContent((xmlNodePtr) attrp)) {
+ RETVAL_STRING(content,1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ xmlFree(content);
+}
+/* }}} */
+
+/* {{{ proto bool domxml_attr_set_value(string content)
+ Set value of attribute */
+PHP_FUNCTION(domxml_attr_set_value)
+{
+ zval *id;
+ xmlAttrPtr attrp;
+ int content_len;
+ char *content;
+
+ DOMXML_PARAM_TWO(attrp, id, le_domxmlattrp, "s", &content, &content_len);
+
+ /* If attribute has children unlink referenced nodes
+ Spec indicates that content is to be overwritten and not appended
+ xmlNodeSetContentLen will take care of removing and freeing the rest */
+ if (attrp->children) {
+ node_list_unlink(((xmlNodePtr) attrp) ->children);
+ }
+ xmlNodeSetContentLen((xmlNodePtr) attrp, content, content_len);
+ RETURN_TRUE;
+
}
/* }}} */
@@ -1840,12 +1872,19 @@
{
zval *id;
xmlNodePtr nodep;
+ xmlChar *content;
DOMXML_GET_THIS_OBJ(nodep, id, le_domxmlpip);
DOMXML_NO_ARGS();
- RETURN_STRING(xmlNodeGetContent(nodep), 1);
+ /* RETURN_STRING(xmlNodeGetContent(nodep), 1); */
+ if (content = xmlNodeGetContent(nodep)) {
+ RETVAL_STRING(content,1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ xmlFree(content);
}
/* }}} */