rrichards Wed Sep 17 15:34:43 2003 EDT
Modified files: (Branch: PHP_4_3)
/php-src/ext/domxml php_domxml.c
Log:
fix some threading issues
fix mem leaks in append_child with attribute nodes
Index: php-src/ext/domxml/php_domxml.c
diff -u php-src/ext/domxml/php_domxml.c:1.218.2.31
php-src/ext/domxml/php_domxml.c:1.218.2.32
--- php-src/ext/domxml/php_domxml.c:1.218.2.31 Tue Sep 9 15:43:44 2003
+++ php-src/ext/domxml/php_domxml.c Wed Sep 17 15:34:42 2003
@@ -16,7 +16,7 @@
+--+
*/
-/* $Id: php_domxml.c,v 1.218.2.31 2003/09/09 19:43:44 msopacua Exp $ */
+/* $Id: php_domxml.c,v 1.218.2.32 2003/09/17 19:34:42 rrichards Exp $ */
/* TODO
* - Support Notation Nodes
@@ -146,6 +146,8 @@
#define DOMXML_LOAD_SUBSTITUTE_ENTITIES 4
#define DOMXML_LOAD_COMPLETE_ATTRS 8
#define DOMXML_LOAD_DONT_KEEP_BLANKS 16
+#define DOMXML_LOAD_FILE 1
+
static int le_domxmldocp;
static int le_domxmldoctypep;
static int le_domxmldtdp;
@@ -170,7 +172,6 @@
static void domxml_error(void *ctx, const char *msg, ...);
static void domxml_error_ext(void *ctx, const char *msg, ...);
static void domxml_error_validate(void *ctx, const char *msg, ...);
-static xmlDocPtr php_dom_xmlSAXParse(xmlSAXHandlerPtr sax, const char *buffer, int
size, int recovery, void *data);
#if defined(LIBXML_XPATH_ENABLED)
static int le_xpathctxp;
@@ -1477,73 +1478,13 @@
}
-static xmlDocPtr php_dom_xmlSAXParse(xmlSAXHandlerPtr sax, const char *buffer, int
size, int recovery, void *data)
-{
-xmlDocPtr ret;
-xmlParserCtxtPtr ctxt;
-domxml_ErrorCtxt errorCtxt;
-char *directory = NULL;
-
-xmlInitParser();
-/*if size == -1, we assume, it's a filename not a inmemory xml doc*/
-if (size == -1) {
- ctxt = (xmlParserCtxt *) xmlCreateFileParserCtxt( buffer);
-} else {
- ctxt = (xmlParserCtxt *) xmlCreateMemoryParserCtxt((xmlChar *) buffer,
size);
-}
-if (ctxt == NULL) {
- return(NULL);
-}
- if (sax != NULL) {
- if (ctxt-sax != NULL)
- xmlFree(ctxt-sax);
- ctxt-sax = sax;
- }
- if (data!=NULL) {
- ctxt-_private=data;
- }
-
-/* store directory name */
- if (size == -1) {
- if ((ctxt-directory == NULL) (directory == NULL))
- directory = xmlParserGetDirectory(buffer);
- if ((ctxt-directory == NULL) (directory != NULL))
- ctxt-directory = (char *) xmlStrdup((xmlChar *) directory);
- }
- errorCtxt.valid = ctxt-vctxt;
- errorCtxt.errors = data;
- errorCtxt.parser = ctxt;
-
- ctxt-sax-error = domxml_error_ext;
- ctxt-sax-warning = domxml_error_ext;
- ctxt-vctxt.userData= (void *) errorCtxt;
- ctxt-vctxt.error= (xmlValidityErrorFunc) domxml_error_validate;
- ctxt-vctxt.warning = (xmlValidityWarningFunc) domxml_error_validate;
-
- xmlParseDocument(ctxt);
-
- if ((ctxt-wellFormed) || recovery) {
- ret = ctxt-myDoc;
- } else {
- ret = NULL;
- xmlFreeDoc(ctxt-myDoc);
- ctxt-myDoc = NULL;
- }
-if (sax != NULL)
-ctxt-sax = NULL;
-
- xmlFreeParserCtxt(ctxt);
-
- return(ret);
-}
-
PHP_MSHUTDOWN_FUNCTION(domxml)
{
#if HAVE_DOMXSLT
xsltCleanupGlobals();
#endif
xmlCleanupParser();
-
+
/* If you want do find memleaks in this module, compile libxml2 with
--with-mem-debug and
uncomment the following line, this will tell you the amount of not freed memory
and the total used memory into apaches error_log */
@@ -2472,20 +2413,37 @@
foundattrp = xmlHasProp(parent, child-name);
else
foundattrp = xmlHasNsProp(parent, child-name,
child-ns-href);
- if ((foundattrp != NULL) (foundattrp != (xmlAttrPtr)
child)) {
- xmlUnlinkNode((xmlNodePtr) foundattrp);
- (void)xmlCopyProp(parent, (xmlAttrPtr) child);
- /* We're in the dark here, what happened to the
parent, let's
-* assume it's handled properly and return the new(?)
parent
-*/
- new_child = parent;
+ if (foundattrp != (xmlAttrPtr) child) {
+ if (foundattrp != NULL) {
+ if (dom_object_get_data((xmlNodePtr)
foundattrp) == NULL) {
+ node_list_unlink(foundattrp-children);
+ xmlUnlinkNode((xmlNodePtr) foundattrp);
+ xmlFreeProp(foundattrp);
+