andrey Tue Jun 24 22:22:49 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/mysql php_mysql.c /php-src/ext/mysqli mysqli.c /php-src/ext/mysqlnd mysqlnd.c mysqlnd_palloc.c Log: Fix remaining valgrind problems with pconn and zval cache HEAD merge will follow tomorrow.
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/php_mysql.c?r1=1.213.2.6.2.16.2.19&r2=1.213.2.6.2.16.2.20&diff_format=u Index: php-src/ext/mysql/php_mysql.c diff -u php-src/ext/mysql/php_mysql.c:1.213.2.6.2.16.2.19 php-src/ext/mysql/php_mysql.c:1.213.2.6.2.16.2.20 --- php-src/ext/mysql/php_mysql.c:1.213.2.6.2.16.2.19 Tue Jun 24 13:19:29 2008 +++ php-src/ext/mysql/php_mysql.c Tue Jun 24 22:22:48 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_mysql.c,v 1.213.2.6.2.16.2.19 2008/06/24 13:19:29 andrey Exp $ */ +/* $Id: php_mysql.c,v 1.213.2.6.2.16.2.20 2008/06/24 22:22:48 andrey Exp $ */ /* TODO: * @@ -365,9 +365,6 @@ void (*handler) (int); handler = signal(SIGPIPE, SIG_IGN); -#ifdef MYSQL_USE_MYSQLND - mysqlnd_end_psession(link->conn); -#endif mysql_close(link->conn); signal(SIGPIPE, handler); @@ -520,6 +517,18 @@ } /* }}} */ + +#ifdef MYSQL_USE_MYSQLND +static int php_mysql_persistent_helper(zend_rsrc_list_entry *le TSRMLS_DC) +{ + if (le->type == le_plink) { + mysqlnd_end_psession(((php_mysql_conn *) le->ptr)->conn); + } + return ZEND_HASH_APPLY_KEEP; +} /* }}} */ +#endif + + /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(mysql) @@ -537,7 +546,9 @@ if (MySG(connect_error)!=NULL) { efree(MySG(connect_error)); } + #ifdef MYSQL_USE_MYSQLND + zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysql_persistent_helper TSRMLS_CC); mysqlnd_palloc_rshutdown(MySG(mysqlnd_thd_zval_cache)); #endif @@ -734,8 +745,9 @@ mysql->conn = mysql_init(persistent); #endif - if (connect_timeout != -1) + if (connect_timeout != -1) { mysql_options(mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout); + } #ifndef MYSQL_USE_MYSQLND if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL) #else @@ -778,12 +790,11 @@ /* ensure that the link did not die */ if (mysql_ping(mysql->conn)) { if (mysql_errno(mysql->conn) == 2006) { -#ifdef MYSQL_USE_MYSQLND - mysqlnd_end_psession(mysql->conn); +#ifndef MYSQL_USE_MYSQLND + if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL) +#else if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0, port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL) -#else - if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL) #endif { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect"); http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/mysqli.c?r1=1.72.2.16.2.17.2.25&r2=1.72.2.16.2.17.2.26&diff_format=u Index: php-src/ext/mysqli/mysqli.c diff -u php-src/ext/mysqli/mysqli.c:1.72.2.16.2.17.2.25 php-src/ext/mysqli/mysqli.c:1.72.2.16.2.17.2.26 --- php-src/ext/mysqli/mysqli.c:1.72.2.16.2.17.2.25 Tue Jun 24 13:19:29 2008 +++ php-src/ext/mysqli/mysqli.c Tue Jun 24 22:22:48 2008 @@ -17,7 +17,7 @@ | Ulf Wendel <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: mysqli.c,v 1.72.2.16.2.17.2.25 2008/06/24 13:19:29 andrey Exp $ + $Id: mysqli.c,v 1.72.2.16.2.17.2.26 2008/06/24 22:22:48 andrey Exp $ */ #ifdef HAVE_CONFIG_H @@ -94,12 +94,8 @@ /* Destructor for mysqli entries in free_links/used_links */ void php_mysqli_dtor_p_elements(void *data) { - MYSQL *mysql = (MYSQL *) data; -#if defined(MYSQLI_USE_MYSQLND) TSRMLS_FETCH(); - - mysqlnd_end_psession(mysql); -#endif + MYSQL *mysql = (MYSQL *) data; mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT); } @@ -232,9 +228,6 @@ MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr; if (mysql->mysql) { if (!mysql->persistent) { -#ifdef MYSQLI_USE_MYSQLND - mysqlnd_end_psession(mysql->mysql); -#endif mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT); } else { zend_rsrc_list_entry *le; @@ -959,6 +952,26 @@ } /* }}} */ + +#ifdef MYSQLI_USE_MYSQLND +static void php_mysqli_persistent_helper_for_every(void *p) +{ + TSRMLS_FETCH(); + mysqlnd_end_psession((MYSQLND *) p); +} /* }}} */ + + +static int php_mysqli_persistent_helper_once(zend_rsrc_list_entry *le TSRMLS_DC) +{ + if (le->type == php_le_pmysqli()) { + mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr; + zend_ptr_stack_apply(&plist->free_links, php_mysqli_persistent_helper_for_every); + } + return ZEND_HASH_APPLY_KEEP; +} /* }}} */ +#endif + + /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(mysqli) @@ -972,6 +985,7 @@ efree(MyG(error_msg)); } #ifdef MYSQLI_USE_MYSQLND + zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_helper_once TSRMLS_CC); mysqlnd_palloc_rshutdown(MyG(mysqlnd_thd_zval_cache)); #endif return SUCCESS; http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd.c?r1=1.5.2.22&r2=1.5.2.23&diff_format=u Index: php-src/ext/mysqlnd/mysqlnd.c diff -u php-src/ext/mysqlnd/mysqlnd.c:1.5.2.22 php-src/ext/mysqlnd/mysqlnd.c:1.5.2.23 --- php-src/ext/mysqlnd/mysqlnd.c:1.5.2.22 Tue Jun 24 13:19:29 2008 +++ php-src/ext/mysqlnd/mysqlnd.c Tue Jun 24 22:22:48 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mysqlnd.c,v 1.5.2.22 2008/06/24 13:19:29 andrey Exp $ */ +/* $Id: mysqlnd.c,v 1.5.2.23 2008/06/24 22:22:48 andrey Exp $ */ #include "php.h" #include "mysqlnd.h" #include "mysqlnd_wireprotocol.h" @@ -466,6 +466,7 @@ { DBG_ENTER("_mysqlnd_end_psession"); /* The thd zval cache is always freed on request shutdown, so this has happened already */ + mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache); conn->zval_cache = NULL; DBG_VOID_RETURN; } http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_palloc.c?r1=1.2.2.10&r2=1.2.2.11&diff_format=u Index: php-src/ext/mysqlnd/mysqlnd_palloc.c diff -u php-src/ext/mysqlnd/mysqlnd_palloc.c:1.2.2.10 php-src/ext/mysqlnd/mysqlnd_palloc.c:1.2.2.11 --- php-src/ext/mysqlnd/mysqlnd_palloc.c:1.2.2.10 Tue Jun 24 13:19:29 2008 +++ php-src/ext/mysqlnd/mysqlnd_palloc.c Tue Jun 24 22:22:48 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mysqlnd_palloc.c,v 1.2.2.10 2008/06/24 13:19:29 andrey Exp $ */ +/* $Id: mysqlnd_palloc.c,v 1.2.2.11 2008/06/24 22:22:48 andrey Exp $ */ #include "php.h" #include "mysqlnd.h" #include "mysqlnd_priv.h" @@ -189,13 +189,43 @@ constructor of the cache. */ static -void mysqlnd_palloc_free_thd_cache(MYSQLND_THD_ZVAL_PCACHE *cache TSRMLS_DC) +void mysqlnd_palloc_free_thd_cache(MYSQLND_THD_ZVAL_PCACHE *thd_cache TSRMLS_DC) { + MYSQLND_ZVAL_PCACHE *global_cache; + mysqlnd_zval **p; + DBG_ENTER("mysqlnd_palloc_free_thd_cache"); - DBG_INF_FMT("cache=%p", cache); + DBG_INF_FMT("thd_cache=%p", thd_cache); - mnd_free(cache->gc_list.ptr_line); - mnd_free(cache); + if ((global_cache = thd_cache->parent)) { + /* + Keep in mind that for pthreads pthread_equal() should be used to be + fully standard compliant. However, the PHP code all-around, incl. the + the Zend MM uses direct comparison. + */ + p = thd_cache->gc_list.ptr_line; + while (p < thd_cache->gc_list.last_added) { + zval_dtor(&(*p)->zv); + p++; + } + + p = thd_cache->gc_list.ptr_line; + + LOCK_PCACHE(global_cache); + while (p < thd_cache->gc_list.last_added) { + (*p)->point_type = MYSQLND_POINTS_FREE; + *(--global_cache->free_list.last_added) = *p; + ++global_cache->free_items; +#ifdef ZTS + memset(&((*p)->thread_id), 0, sizeof(THREAD_T)); +#endif + p++; + } + UNLOCK_PCACHE(global_cache); + + } + mnd_free(thd_cache->gc_list.ptr_line); + mnd_free(thd_cache); DBG_VOID_RETURN; } @@ -508,56 +538,9 @@ /* {{{ _mysqlnd_palloc_rshutdown */ PHPAPI void _mysqlnd_palloc_rshutdown(MYSQLND_THD_ZVAL_PCACHE * thd_cache TSRMLS_DC) { - MYSQLND_ZVAL_PCACHE *cache; - mysqlnd_zval **p; - DBG_ENTER("_mysqlnd_palloc_rshutdown"); DBG_INF_FMT("cache=%p", thd_cache); - - if (!thd_cache || !(cache = thd_cache->parent)) { - return; - } - - /* - !!! 080624 !!! - If the user has used Persistent Connections the reference counter - of the cache is not 1 but > 1 . Because the Pconns don't are not signalised - during RSHUT, then we need to take care here to decrease the counter. - A more proper fix will be to array_walk our pconns in RSHUT and ask them to - free their thd reference. This should be implemented sooner or later! - */ - - /* - Keep in mind that for pthreads pthread_equal() should be used to be - fully standard compliant. However, the PHP code all-around, incl. the - the Zend MM uses direct comparison. - */ - p = thd_cache->gc_list.ptr_line; - while (p < thd_cache->gc_list.last_added) { - zval_dtor(&(*p)->zv); - p++; - } - - p = thd_cache->gc_list.ptr_line; - - LOCK_PCACHE(cache); - /* We need to decrease Main cache's references as pconns don't clean correctly */ - cache->references -= (thd_cache->references - 1); /* we start with 1 initial reference */ - while (p < thd_cache->gc_list.last_added) { - (*p)->point_type = MYSQLND_POINTS_FREE; - *(--cache->free_list.last_added) = *p; - ++cache->free_items; -#ifdef ZTS - memset(&((*p)->thread_id), 0, sizeof(THREAD_T)); -#endif - p++; - } - UNLOCK_PCACHE(cache); - - /* We need to decrease thd cache's references as pconns don't clean correctly. See above! */ - thd_cache->references = 1; mysqlnd_palloc_free_thd_cache_reference(&thd_cache); - DBG_VOID_RETURN; } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php