From 9137acc7ecdf1542fe6fda5056a0273359682735 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 27 Feb 2014 08:45:16 +0100 Subject: Fixed Bug #66762 Segfault in mysqli_stmt::bind_result() when link closed Each new mysqli_stmt now increase the refcount of the link object. So the link is really destroy after all statements. Only implemented with libmysqlclient, as mysqlnd already implement this internally. So, libmysqlclient and mysqlnd have the same behavior. --- ext/mysqli/mysqli.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/mysqli/mysqli.c') diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 4e4ed5b2ab..cbeb18349e 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -176,8 +176,11 @@ void php_clear_stmt_bind(MY_STMT *stmt TSRMLS_DC) php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE); /* Clean output bind */ php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT); -#endif + if (stmt->link_handle) { + zend_objects_store_del_ref_by_handle(stmt->link_handle TSRMLS_CC); + } +#endif if (stmt->query) { efree(stmt->query); } @@ -1055,6 +1058,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 TSRMLS_CC); +#endif mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE)); mysqli_resource->ptr = (void *)stmt; -- cgit v1.2.1