diff options
author | Andrey Hristov <andrey@php.net> | 2008-09-19 11:35:37 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2008-09-19 11:35:37 +0000 |
commit | 722b9135d9b4c43fab62ff73ea9e106e1455d5da (patch) | |
tree | 844ce100011cf70d6aa55e2babedaa9f7f9290b2 | |
parent | d17dab311f96f6b3ddeac4133b98ceb59fa0b9b0 (diff) | |
download | php-git-722b9135d9b4c43fab62ff73ea9e106e1455d5da.tar.gz |
Fix for bug#46019 MySQLi::init() leaks memory
-rw-r--r-- | ext/mysqli/mysqli.c | 2 | ||||
-rw-r--r-- | ext/mysqli/mysqli_api.c | 8 | ||||
-rw-r--r-- | ext/mysqli/tests/bug46109.phpt | 18 |
3 files changed, 26 insertions, 2 deletions
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 89bee8c58f..d3a500b579 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1255,7 +1255,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags } else { ZVAL_STRINGL(res, row[i], field_len[i], 1); } - + if (m if (fetchtype & MYSQLI_NUM) { add_index_zval(return_value, i, res); } diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 44f103628c..be5a5223e0 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1364,7 +1364,13 @@ PHP_FUNCTION(mysqli_info) PHP_FUNCTION(mysqli_init) { MYSQLI_RESOURCE *mysqli_resource; - MY_MYSQL *mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL)); + MY_MYSQL *mysql; + + if (getThis() && instanceof_function(Z_OBJCE_P(getThis()), mysqli_link_class_entry TSRMLS_CC)) { + return; + } + + mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL)); #if !defined(MYSQLI_USE_MYSQLND) if (!(mysql->mysql = mysql_init(NULL))) diff --git a/ext/mysqli/tests/bug46109.phpt b/ext/mysqli/tests/bug46109.phpt new file mode 100644 index 0000000000..bbb2903ab6 --- /dev/null +++ b/ext/mysqli/tests/bug46109.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #46109 (MySQLi::init - Memory leaks) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $mysqli = new mysqli(); + $mysqli->init(); + $mysqli->init(); + echo "done"; +?> +--EXPECTF-- +done |