-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ext/xml: Use object instead of resource
Use an XmlParser object instead of a resource. This is an internal representation change, not a conversion to OO APIs. XmlParser objects cannot be explicitly constructed, they are created through the usual xml_parser_* APIs. This change allows us to provide a proper get_gc() implementation, thus resolving bugs #72793 and #76874. xml_parser_free() is a no-op now and need not be called anymore.
- Loading branch information
Showing
5 changed files
with
180 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
Bug #72793: xml_parser_free leaks mem when execute xml_set_object | ||
--FILE-- | ||
<?php | ||
|
||
class xml { | ||
var $parser; | ||
|
||
function __construct() | ||
{ | ||
$this->parser = xml_parser_create(); | ||
xml_set_object($this->parser, $this); | ||
} | ||
|
||
function parse($data) | ||
{ | ||
xml_parse($this->parser, $data); | ||
} | ||
|
||
function free(){ | ||
xml_parser_free($this->parser); | ||
} | ||
} | ||
|
||
$xml_test = '<?xml version="1.0" encoding="utf-8"?><test></test>'; | ||
$xml_parser = new xml(); | ||
$xml_parser->parse($xml_test); | ||
$xml_parser->free(); | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Bug #76874: xml_parser_free() should never leak memory | ||
--FILE-- | ||
<?php | ||
|
||
class c | ||
{ | ||
private $xml; | ||
private $test; | ||
|
||
public function test() | ||
{ | ||
$this->xml = xml_parser_create(); | ||
xml_set_character_data_handler($this->xml, array(&$this, 'handle_cdata')); | ||
xml_parser_free($this->xml); | ||
} | ||
|
||
public function handle_cdata(&$parser, $data) | ||
{ | ||
} | ||
} | ||
|
||
$object = new c(); | ||
$object->test(); | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
Oops, something went wrong.