Attached is a patch for the xml extension which fixes the segfault with
objects such as in bug 27821 as well as a few other scripts i've seen
floating around.

Is there a reason why zval_add_ref in xml_set_object was commented out? Yes
I already asked thies and was directed here.
It doesnt make sense that this function will dtor the object but not
increment the ref on the object, which in bug 27821, the engine ended up
destyoing the object while running the methods of the object.

The changes in compat.c are unrelated mem leak fixes

Rob
Index: compat.c
===================================================================
RCS file: /repository/php-src/ext/xml/compat.c,v
retrieving revision 1.31
diff -u -r1.31 compat.c
--- compat.c    24 Feb 2004 12:03:32 -0000      1.31
+++ compat.c    1 Apr 2004 15:44:41 -0000
@@ -232,6 +232,7 @@
 
                _build_comment(comment, xmlStrlen(comment), &d_comment, 
&d_comment_len);
                parser->h_default(parser->user, d_comment, d_comment_len);
+               xmlFree(d_comment);
        }
 }
 
@@ -257,6 +258,7 @@
                
                _build_entity(name, xmlStrlen(name), &entity, &len);
                parser->h_default(parser->user, (const xmlChar *) entity, len);
+               xmlFree(entity);
        }
 
        return NULL;
Index: xml.c
===================================================================
RCS file: /repository/php-src/ext/xml/xml.c,v
retrieving revision 1.150
diff -u -r1.150 xml.c
--- xml.c       23 Feb 2004 16:19:39 -0000      1.150
+++ xml.c       1 Apr 2004 15:44:42 -0000
@@ -1145,9 +1145,9 @@
        parser->object = *mythis;
 
        /* please leave this commented - or ask [EMAIL PROTECTED] before doing it 
(again) */
-/* #ifdef ZEND_ENGINE_2
-       zval_add_ref(&parser->object); 
-#endif */
+#ifdef ZEND_ENGINE_2
+       zval_add_ref(&parser->object);
+#endif
 
        RETVAL_TRUE;
 }
@@ -1486,6 +1486,12 @@
 
        ZEND_FETCH_RESOURCE(parser,xml_parser *, pind, -1, "XML Parser", 
le_xml_parser);
 
+#ifdef ZEND_ENGINE_2
+       if (parser->object) {
+               zval_ptr_dtor(&parser->object);
+       }
+#endif
+
        if (zend_list_delete(parser->index) == FAILURE) {
                RETURN_FALSE;
        }

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to