Problem with refcounts and destructors (#2206)
| From: | Thies C. Arntzen | Date: | Wed, 01 Sep 1999 12:47:02 +0000 |
| Subject: | Problem with refcounts and destructors (#2206) | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3962@lists.php.net to get a copy of this message | ||
hi,
i've reproduced this one (please apply attached patch to mysql.c to see the problem).
script:
<?
$conn=mysql_connect("127.0.0.1");
for ($inx = 0; $inx < 10; $inx++) {
$r = mysql_db_query("test", "select * from phptest");
$array = mysql_fetch_array($r);
mysql_free_result($r);
}
echo "-----------------------end--------------\n";flush();
?>
this script does *NOT* (sorry for the emphasis) free the mysql-results while the script is running.
./php ./mysql.php3
new_result 0x081529e8
new_result 0x08153098
new_result 0x08153668
new_result 0x08153778
new_result 0x081538a8
new_result 0x081539b8
new_result 0x08153ac8
new_result 0x08153bd8
new_result 0x08153ce8
new_result 0x08153df8
Content-Type: text/html
-----------------------end--------------
_free_mysql_result 0x081529e8
_free_mysql_result 0x08153098
_free_mysql_result 0x08153668
_free_mysql_result 0x08153778
_free_mysql_result 0x081538a8
_free_mysql_result 0x081539b8
_free_mysql_result 0x08153ac8
_free_mysql_result 0x08153bd8
_free_mysql_result 0x08153ce8
_free_mysql_result 0x08153df8
changing line 6 of the script to:
$array = mysql_fetch_array(&$r);
^ that's the trick
will get you:
./php ./mysql.php3
new_result 0x081529e8
_free_mysql_result 0x081529e8
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
new_result 0x08153050
_free_mysql_result 0x08153050
Content-Type: text/html
-----------------------end--------------
but you need to call mysql_free_result:
for ($inx = 0; $inx < 10; $inx++) {
$r = mysql_db_query("test", "select * from phptest");
$array = mysql_fetch_array(&$r);
// mysql_free_result($r);
}
gets you:
new_result 0x08153098
new_result 0x08153668
new_result 0x08153778
new_result 0x081538a8
new_result 0x081539b8
new_result 0x08153ac8
new_result 0x08153bd8
new_result 0x08153ce8
new_result 0x08153df8
Content-Type: text/html
-----------------------end--------------
_free_mysql_result 0x081529e8
_free_mysql_result 0x08153098
_free_mysql_result 0x08153668
_free_mysql_result 0x08153778
_free_mysql_result 0x081538a8
_free_mysql_result 0x081539b8
_free_mysql_result 0x08153ac8
_free_mysql_result 0x08153bd8
_free_mysql_result 0x08153ce8
_free_mysql_result 0x08153df8
which means that passing resource-id around ($r in this case) will cause problems.
tc
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany