summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/mysqli/mysqli.c16
-rw-r--r--ext/mysqli/mysqli_api.c11
2 files changed, 22 insertions, 5 deletions
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c
index a72494ff5a..75996eab4d 100644
--- a/ext/mysqli/mysqli.c
+++ b/ext/mysqli/mysqli.c
@@ -43,9 +43,11 @@ void php_clear_stmt_bind(STMT *stmt)
{
unsigned int i;
- if (stmt->stmt && stmt->stmt->mysql->host) {
- mysql_stmt_close(stmt->stmt);
- }
+ /*
+ * we don't need to call mysql_stmt_close here.
+ * in case mysqli_stmt_close wasn't called, all
+ * statements will be freed via mysql_close
+ */
if (stmt->var_cnt) {
for (i = 0; i < stmt->var_cnt; i++) {
@@ -79,6 +81,13 @@ static void mysqli_objects_dtor(void *object, zend_object_handle handle TSRMLS_D
if (intern->zo.ce == mysqli_link_class_entry) {
MYSQL *mysql = (MYSQL *)intern->ptr;
if (mysql) {
+ /*
+ * Don't free mysql if there exist
+ * non closed statements
+ */
+ if (mysql->stmts) {
+ mysql->free_me = 0;
+ }
mysql_close(mysql);
}
} else if (intern->zo.ce == mysqli_stmt_class_entry) { /* stmt object */
@@ -92,7 +101,6 @@ static void mysqli_objects_dtor(void *object, zend_object_handle handle TSRMLS_D
mysql_free_result(res);
}
}
-
zend_objects_destroy_object(object, handle TSRMLS_CC);
}
/* }}} */
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index e37a120a00..070f629b6a 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -384,6 +384,15 @@ PHP_FUNCTION(mysqli_close)
}
MYSQLI_FETCH_RESOURCE(mysql, MYSQL *, &mysql_link, "mysqli_link");
+
+ /*
+ * Don't free initial struct if there exist
+ * non closed statements
+ */
+ if (mysql->stmts) {
+ mysql->free_me = 0;
+ }
+
mysql_close(mysql);
MYSQLI_CLEAR_RESOURCE(&mysql_link);
RETURN_TRUE;
@@ -1519,7 +1528,7 @@ PHP_FUNCTION(mysqli_stmt_close)
return;
}
MYSQLI_FETCH_RESOURCE(stmt, STMT *, &mysql_stmt, "mysqli_stmt");
-
+ mysql_stmt_close(stmt->stmt);
php_clear_stmt_bind(stmt);
MYSQLI_CLEAR_RESOURCE(&mysql_stmt);
RETURN_TRUE;