php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #66762
Patch mysqli-protect-link.patch revision 2014-02-25 07:44 UTC by remi@php.net
revision 2014-02-25 07:32 UTC by remi@php.net
revision 2014-02-24 18:21 UTC by remi@php.net
revision 2014-02-24 16:35 UTC by remi@php.net

Patch mysqli-protect-link.patch for MySQLi related Bug #66762

Patch version 2014-02-24 18:21 UTC

Return to Bug #66762 | Download this patch
This patch is obsolete

Obsoleted by patches:

This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: remi@php.net

diff -up ext/mysqli/mysqli_api.c.orig ext/mysqli/mysqli_api.c
--- ext/mysqli/mysqli_api.c.orig	2014-02-18 17:14:48.000000000 +0100
+++ ext/mysqli/mysqli_api.c	2014-02-24 19:19:52.321098290 +0100
@@ -1869,6 +1869,10 @@ PHP_FUNCTION(mysqli_prepare)
 		efree(stmt);
 		RETURN_FALSE;
 	}
+#ifndef MYSQLI_USE_MYSQLND
+	stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
+	zend_objects_store_add_ref_by_handle(stmt->link_handle);
+#endif
 
 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
 	mysqli_resource->ptr = (void *)stmt;
@@ -2413,6 +2417,10 @@ PHP_FUNCTION(mysqli_stmt_init)
 		efree(stmt);
 		RETURN_FALSE;
 	}
+#ifndef MYSQLI_USE_MYSQLND
+	stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
+	zend_objects_store_add_ref_by_handle(stmt->link_handle);
+#endif
 
 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
 	mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
diff -up ext/mysqli/mysqli.c.orig ext/mysqli/mysqli.c
--- ext/mysqli/mysqli.c.orig	2014-02-18 17:14:48.000000000 +0100
+++ ext/mysqli/mysqli.c	2014-02-24 19:18:51.112895737 +0100
@@ -176,6 +176,10 @@ void php_clear_stmt_bind(MY_STMT *stmt T
 	php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
 	/* Clean output bind */
 	php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
+
+	if (stmt->link_handle) {
+	    zend_objects_store_del_ref_by_handle(stmt->link_handle TSRMLS_CC);
+	}
 #endif
 
 	if (stmt->query) {
@@ -1069,6 +1073,10 @@ PHP_FUNCTION(mysqli_stmt_construct)
 		efree(stmt);
 		RETURN_FALSE;
 	}
+#ifndef MYSQLI_USE_MYSQLND
+	stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
+	zend_objects_store_add_ref_by_handle(stmt->link_handle);
+#endif
 
 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
 	mysqli_resource->ptr = (void *)stmt;
diff -up ext/mysqli/php_mysqli_structs.h.orig ext/mysqli/php_mysqli_structs.h
--- ext/mysqli/php_mysqli_structs.h.orig	2014-02-18 17:14:48.000000000 +0100
+++ ext/mysqli/php_mysqli_structs.h	2014-02-24 19:15:27.567222173 +0100
@@ -116,6 +116,10 @@ typedef struct {
 	BIND_BUFFER	param;
 	BIND_BUFFER	result;
 	char		*query;
+#ifndef MYSQLI_USE_MYSQLND
+	/* used to manage refcount with libmysql (already implement in mysqlnd) */
+	zend_object_handle link_handle;
+#endif
 } MY_STMT;
 
 typedef struct {
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC