cvs: pear /XML_DTD/DTD XmlParser.php

From: Date: Tue, 28 Apr 2009 01:56:13 +0000
Subject: cvs: pear /XML_DTD/DTD XmlParser.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-55993@lists.php.net to get a copy of this message
ifeghali Tue Apr 28 01:56:13 2009 UTC Modified files: /pear/XML_DTD/DTD XmlParser.php Log: - Due to php 4 and 5 diferences in object handling, we had to try another approach to get the parser working with php 4. the previous parser was working only for php 5. - Circular reference fixed (memory leak) http://cvs.php.net/viewvc.cgi/pear/XML_DTD/DTD/XmlParser.php?r1=1.1&r2=1.2&diff_format=u Index: pear/XML_DTD/DTD/XmlParser.php diff -u pear/XML_DTD/DTD/XmlParser.php:1.1 pear/XML_DTD/DTD/XmlParser.php:1.2 --- pear/XML_DTD/DTD/XmlParser.php:1.1 Sun Jan 18 22:50:09 2009 +++ pear/XML_DTD/DTD/XmlParser.php Tue Apr 28 01:56:13 2009 @@ -11,7 +11,7 @@ * * LICENSE: * - * Copyright (c) 2008 Igor Feghali + * Copyright (c) 2008-2009 Igor Feghali * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,9 +41,9 @@ * @category XML * @package XML_DTD * @author Igor Feghali <ifeghali@php.net> - * @copyright 2008 Igor Feghali + * @copyright 2008-2009 Igor Feghali * @license http://opensource.org/licenses/bsd-license New BSD License - * @version CVS: $Id: XmlParser.php,v 1.1 2009/01/18 22:50:09 ifeghali Exp $ + * @version CVS: $Id: XmlParser.php,v 1.2 2009/04/28 01:56:13 ifeghali Exp $ * @link http://pear.php.net/package/XML_DTD */ @@ -75,7 +75,6 @@ { var $children = array(); var $ptr = null; - var $stack = array(); var $folding = true; /** @@ -89,7 +88,7 @@ function XML_DTD_XmlParser() { parent::XML_Parser(); - $this->ptr = &$this; + $this->ptr =& $this; } /** @@ -104,7 +103,7 @@ */ function factory($xml) { - $p = &new XML_DTD_XmlParser(); + $p =& new XML_DTD_XmlParser(); $result = $p->setInputFile($xml); if (PEAR::isError($result)) { @@ -116,6 +115,12 @@ return $result; } + /** + * Preventing the circular reference memory leak. + * See: http://bugs.php.net/bug.php?id=33595 + */ + unset($p->_handlerObj, $p->ptr); + return $p->children[0]; } @@ -131,15 +136,15 @@ */ function startHandler($xp, $name, $attr) { - $e = new XML_DTD_XmlElement(); + $e =& new XML_DTD_XmlElement(); $e->name = $name; $e->attr = $attr; $e->lineno = @xml_get_current_line_number($xp); $e->colno = @xml_get_current_column_number($xp); + $e->parent =& $this->ptr; - $this->ptr->children[] = $e; - array_push($this->stack, $this->ptr); - $this->ptr = &$e; + $this->ptr->children[] =& $e; + $this->ptr =& $e; } /** @@ -153,7 +158,15 @@ */ function endHandler($xp, $name) { - $this->ptr = array_pop($this->stack); + $tmp =& $this->ptr; + $this->ptr =& $this->ptr->parent; + + /** + * We do not need the reference to the parent object anymore. Clean it + * up to prevent the circular reference memory leak. + * See: http://bugs.php.net/bug.php?id=33595 + */ + unset($tmp->parent); } /** @@ -192,6 +205,7 @@ var $content = 'EMPTY'; var $attr = array(); var $children = array(); + var $parent = null; var $lineno = 0; var $colno = 0;

« previous php.pear.cvs (#55993) next »