php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #78555
Patch mysqli_dbo_cleanup revision 2019-09-17 17:24 UTC by erik at coretech dot se

Patch mysqli_dbo_cleanup for MySQLi related Bug #78555

Patch version 2019-09-17 17:24 UTC

Return to Bug #78555 | Download this patch
Patch Revisions:

Developer: erik@coretech.se

--- ext/mysqli/php_mysqli_structs.h	2019-08-28 00:52:45.000000000 +0200
+++ ext/mysqli/php_mysqli_structs.h	2019-09-17 19:11:26.928702275 +0200
@@ -127,6 +127,7 @@
 	php_stream		*li_stream;
 	unsigned int 	multi_query;
 	zend_bool		persistent;
+	zend_bool		disable_cleanup; /* Disable dtor cleanup */
 #if defined(MYSQLI_USE_MYSQLND)
 	int				async_result_fetch_type;
 #endif
--- ext/mysqli/mysqli_fe.h	2019-08-28 00:52:45.000000000 +0200
+++ ext/mysqli/mysqli_fe.h	2019-09-17 19:18:14.903138392 +0200
@@ -34,6 +34,7 @@
 PHP_FUNCTION(mysqli_connect_error);
 PHP_FUNCTION(mysqli_data_seek);
 PHP_FUNCTION(mysqli_debug);
+PHP_FUNCTION(mysqli_disable_cleanup);
 PHP_FUNCTION(mysqli_dump_debug_info);
 PHP_FUNCTION(mysqli_errno);
 PHP_FUNCTION(mysqli_error);
--- ext/mysqli/mysqli_fe.c	2019-08-28 00:52:45.000000000 +0200
+++ ext/mysqli/mysqli_fe.c	2019-09-17 19:18:17.822053034 +0200
@@ -217,6 +217,11 @@
 	ZEND_ARG_INFO(0, debug_options)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_disable_cleanup, 0, 0, 2)
+	MYSQLI_ZEND_ARG_OBJ_INFO_LINK()
+	ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_result_and_fieldnr, 0, 0, 2)
 	MYSQLI_ZEND_ARG_OBJ_INFO_RESULT()
 	ZEND_ARG_INFO(0, field_nr)
@@ -401,7 +406,6 @@
 ZEND_BEGIN_ARG_INFO_EX(arginfo_mysqli_no_options, 0, 0, 0)
 ZEND_END_ARG_INFO()
 
-
 /* {{{ mysqli_functions[]
  *
  * Every user visible function must have an entry in mysqli_functions[].
@@ -420,6 +424,7 @@
 	PHP_FE(mysqli_data_seek,							arginfo_mysqli_data_seek)
 	PHP_FE(mysqli_dump_debug_info,						arginfo_mysqli_only_link)
 	PHP_FE(mysqli_debug,								arginfo_mysqli_debug)
+	PHP_FE(mysqli_disable_cleanup,							arginfo_mysqli_disable_cleanup)
 #if defined(HAVE_EMBEDDED_MYSQLI)
 	PHP_FE(mysqli_embedded_server_end,					NULL)
 	PHP_FE(mysqli_embedded_server_start,				NULL)
@@ -553,6 +558,7 @@
 	PHP_FALIAS(connect, mysqli_connect, arginfo_mysqli_connect)
 	PHP_FALIAS(dump_debug_info, mysqli_dump_debug_info, arginfo_mysqli_no_params)
 	PHP_FALIAS(debug, mysqli_debug, arginfo_mysqli_debug)
+	PHP_FALIAS(disable_cleanup, mysqli_disable_cleanup, arginfo_mysqli_disable_cleanup)
 #ifdef HAVE_MYSQLI_GET_CHARSET
 	PHP_FALIAS(get_charset, mysqli_get_charset, arginfo_mysqli_no_params)
 #endif
--- ext/mysqli/mysqli_api.c	2019-08-28 00:52:45.000000000 +0200
+++ ext/mysqli/mysqli_api.c	2019-09-17 19:38:43.038943433 +0200
@@ -804,6 +804,25 @@
 }
 /* }}} */
 
+/* {{{ proto void mysqli_disable_cleanup(object link, bool value)
+   Turn link cleanup on or off when the object is destroyed
+*/
+PHP_FUNCTION(mysqli_disable_cleanup)
+{
+	MY_MYSQL *mysql;
+	zval *mysql_link;
+	zend_bool value;
+
+	if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &value) == FAILURE) {
+		return;
+	}
+	MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
+	mysql->disable_cleanup = value;
+	RETURN_TRUE;
+}
+/* }}} */
+
+
 /* {{{ proto bool mysqli_dump_debug_info(object link)
 */
 PHP_FUNCTION(mysqli_dump_debug_info)
@@ -1513,6 +1532,7 @@
 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
 	mysqli_resource->ptr = (void *)mysql;
 	mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
+	mysql->disable_cleanup = FALSE;
 
 	if (!is_method) {
 		MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
--- ext/mysqli/mysqli.c	2019-08-28 00:52:45.000000000 +0200
+++ ext/mysqli/mysqli.c	2019-09-17 19:53:59.753183125 +0200
@@ -216,11 +216,13 @@
 
 	if (my_res && my_res->ptr) {
 		MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
-		if (mysql->mysql) {
-			php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status);
+		if(!mysql->disable_cleanup) {
+			if (mysql->mysql) {
+				php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status);
+			}
+			php_clear_mysql(mysql);
+			efree(mysql);
 		}
-		php_clear_mysql(mysql);
-		efree(mysql);
 		my_res->status = MYSQLI_STATUS_UNKNOWN;
 	}
 	mysqli_objects_free_storage(object);

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 23:01:29 2019 UTC