Bug #63486 [PATCH]: mysqli_free_result leave the resource variable in a messy state

From: Date: Sun, 11 Nov 2012 12:53:01 +0000
Subject: Bug #63486 [PATCH]: mysqli_free_result leave the resource variable in a messy state
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-174629@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63486&edit=1

 ID:                 63486
 Patch added by:     derick@php.net
 Reported by:        derick@php.net
 Summary:            mysqli_free_result leave the resource variable in a
                     messy state
 Status:             Open
 Type:               Bug
 Package:            MySQLi related
 PHP Version:        5.4.8
 Block user comment: N
 Private report:     N

 New Comment:

The following patch has been added/updated:

Patch Name: mysqli-clear-result-cleanup
Revision:   1352638381
URL:        https://bugs.php.net/patch-display.php?bug=63486&patch=mysqli-clear-result-cleanup&revision=1352638381


Previous Comments:
------------------------------------------------------------------------
[2012-11-11 12:52:02] derick@php.net

Description:
------------
An Xdebug user filed the following report: http://bugs.xdebug.org/view.php?id=900

I've just investigated this, and found out that this is something I can't fix in Xdebug.
mysqli_free_result() destroys the internal object, but leaves the resource (in your case, $rs) in a
silly state. All Xdebug does internally is basically a var_dump( $rs ), and after it is freed with
mysqli_free_result(), that throws exactly the same error (without Xdebug). This can however, easily
be fixed in the MySQLi extension with the attached patch. The patch applies to PHP 5.4, but this
also a problem in master and PHP 5.3. It is also possible, that other mysqli_free_* functions can
benefit from a similar construct.

Test script:
---------------
<?php

$con = mysqli_init();
mysqli_real_connect($con, '127.0.0.1', 'root', 'xxxxx');
$rs = mysqli_query($con, 'show schemas');
$row = mysqli_fetch_object($rs);
mysqli_free_result($rs);

echo "hi mom";
var_dump( $rs );
?>


Expected result:
----------------
The expected result is perhaps something like "NULL" (which my patch makes it do).

Actual result:
--------------
hi mom
Warning: var_dump(): Couldn't fetch mysqli_result in
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10

Call Stack:
    0.0002     662616   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0
    0.0032     672792   2. var_dump(class mysqli_result { public $current_field = NULL; public
$field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL })
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10


Warning: var_dump(): Couldn't fetch mysqli_result in
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10

Call Stack:
    0.0002     662616   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0
    0.0032     672792   2. var_dump(class mysqli_result { public $current_field = NULL; public
$field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL })
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10


Warning: var_dump(): Property access is not allowed yet in
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10

Call Stack:
    0.0002     662616   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0
    0.0032     672792   2. var_dump(class mysqli_result { public $current_field = NULL; public
$field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL })
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10


Warning: var_dump(): Couldn't fetch mysqli_result in
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10

Call Stack:
    0.0002     662616   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0
    0.0032     672792   2. var_dump(class mysqli_result { public $current_field = NULL; public
$field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL })
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10


Warning: var_dump(): Property access is not allowed yet in
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10

Call Stack:
    0.0002     662616   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0
    0.0032     672792   2. var_dump(class mysqli_result { public $current_field = NULL; public
$field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL })
/home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10

class mysqli_result#2 (5) {
  public $current_field =>
  NULL
  public $field_count =>
  NULL
  public $lengths =>
  NULL
  public $num_rows =>
  NULL
  public $type =>
  NULL
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63486&edit=1


Thread (24 messages)

« previous php.bugs (#174629) next »