]> granicus.if.org Git - php/commitdiff
Fix for bug#46019 MySQLi::init() leaks memory
authorAndrey Hristov <andrey@php.net>
Fri, 19 Sep 2008 11:35:37 +0000 (11:35 +0000)
committerAndrey Hristov <andrey@php.net>
Fri, 19 Sep 2008 11:35:37 +0000 (11:35 +0000)
ext/mysqli/mysqli.c
ext/mysqli/mysqli_api.c
ext/mysqli/tests/bug46109.phpt [new file with mode: 0644]

index 89bee8c58f173189fd2e0ab195d506fe23968d81..d3a500b579ce0e253c30256e268900d276f318b5 100644 (file)
@@ -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);
                        }
index 44f103628c506a0e9eb215de96d35f1c88b3f283..be5a5223e0a0a8307091a8729d3bb2e3e247d497 100644 (file)
@@ -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 (file)
index 0000000..bbb2903
--- /dev/null
@@ -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