andrey          Mon Aug  6 15:11:46 2007 UTC

  Modified files:              
    /php-src/ext/mysql  php_mysql.c 
    /php-src/ext/mysqlnd        mysqlnd.c mysqlnd_priv.h mysqlnd_result.c 
                                mysqlnd_statistics.h mysqlnd_wireprotocol.c 
  Log:
  Fix crashes with pconn in ext/mysql
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/php_mysql.c?r1=1.239&r2=1.240&diff_format=u
Index: php-src/ext/mysql/php_mysql.c
diff -u php-src/ext/mysql/php_mysql.c:1.239 php-src/ext/mysql/php_mysql.c:1.240
--- php-src/ext/mysql/php_mysql.c:1.239 Tue Jul 24 16:13:25 2007
+++ php-src/ext/mysql/php_mysql.c       Mon Aug  6 15:11:46 2007
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
  
-/* $Id: php_mysql.c,v 1.239 2007/07/24 16:13:25 andrey Exp $ */
+/* $Id: php_mysql.c,v 1.240 2007/08/06 15:11:46 andrey Exp $ */
 
 /* TODO:
  *
@@ -800,6 +800,10 @@
 #endif
                                        mysql_options(mysql->conn, 
MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));
                                }
+                       } else {
+#ifdef HAVE_MYSQLND
+                               mysqlnd_restart_psession(mysql->conn);
+#endif
                        }
                }
                ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd.c
diff -u php-src/ext/mysqlnd/mysqlnd.c:1.2 php-src/ext/mysqlnd/mysqlnd.c:1.3
--- php-src/ext/mysqlnd/mysqlnd.c:1.2   Fri Aug  3 16:32:26 2007
+++ php-src/ext/mysqlnd/mysqlnd.c       Mon Aug  6 15:11:46 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd.c,v 1.2 2007/08/03 16:32:26 andrey Exp $ */
+/* $Id: mysqlnd.c,v 1.3 2007/08/06 15:11:46 andrey Exp $ */
 
 #include "php.h"
 #include "mysqlnd.h"
@@ -27,6 +27,7 @@
 #include "mysqlnd_result.h"
 #include "mysqlnd_statistics.h"
 #include "mysqlnd_charset.h"
+#include "php_ini.h"
 #include "ext/standard/basic_functions.h"
 #include "ext/standard/php_lcg.h"
 #include "ext/standard/info.h"
@@ -263,7 +264,8 @@
                                        SET_ERROR_AFF_ROWS(conn);
                                } else {
                                        SET_NEW_MESSAGE(conn->last_message, 
conn->last_message_len,
-                                                                       
ok_response.message, ok_response.message_len);
+                                                                       
ok_response.message, ok_response.message_len,
+                                                                       
conn->persistent);
 
                                        conn->upsert_status.warning_count = 
ok_response.warning_count;
                                        conn->upsert_status.server_status = 
ok_response.server_status;
@@ -389,6 +391,11 @@
 PHPAPI void mysqlnd_restart_psession(MYSQLND *conn) 
 {
        MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CONNECT_REUSED);
+       /* Free here what should not be seen by the next script */
+       if (conn->last_message) {
+               pefree(conn->last_message, conn->persistent);
+               conn->last_message = NULL;
+       }
 }
 /* }}} */
 
@@ -613,7 +620,8 @@
                conn->upsert_status.server_status = greet_packet.server_status;
                conn->upsert_status.affected_rows = 0;
                SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
-                                               ok_packet.message, 
ok_packet.message_len);
+                                               ok_packet.message, 
ok_packet.message_len,
+                                               conn->persistent);
 
                SET_EMPTY_ERROR(conn->error_info);
 
@@ -1661,7 +1669,7 @@
 
 /* {{{ PHP_MINIT_FUNCTION
  */
-PHP_MINIT_FUNCTION(mysqlnd)
+static PHP_MINIT_FUNCTION(mysqlnd)
 {
        REGISTER_INI_ENTRIES();
 
@@ -1673,7 +1681,7 @@
 
 /* {{{ PHP_MSHUTDOWN_FUNCTION
  */
-PHP_MSHUTDOWN_FUNCTION(mysqlnd)
+static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
 {
        mysqlnd_library_end();
 
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_priv.h?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_priv.h
diff -u php-src/ext/mysqlnd/mysqlnd_priv.h:1.2 
php-src/ext/mysqlnd/mysqlnd_priv.h:1.3
--- php-src/ext/mysqlnd/mysqlnd_priv.h:1.2      Fri Aug  3 16:32:26 2007
+++ php-src/ext/mysqlnd/mysqlnd_priv.h  Mon Aug  6 15:11:46 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd_priv.h,v 1.2 2007/08/03 16:32:26 andrey Exp $ */
+/* $Id: mysqlnd_priv.h,v 1.3 2007/08/06 15:11:46 andrey Exp $ */
 
 #ifndef MYSQLND_PRIV_H
 #define MYSQLND_PRIV_H
@@ -109,10 +109,10 @@
 #define SET_ERROR_AFF_ROWS(s)  (s)->upsert_status.affected_rows = 
(mynd_ulonglong) ~0
 
 /* Error handling */
-#define SET_NEW_MESSAGE(buf, buf_len, message, len) \
+#define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
        {\
                if ((buf)) { \
-                       efree((buf)); \
+                       pefree((buf), (persistent)); \
                } \
                (buf) = (message); \
                (buf_len) = (len); \
@@ -120,10 +120,10 @@
                (message) = NULL; \
        }
 
-#define SET_EMPTY_MESSAGE(buf, buf_len) \
+#define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
        {\
                if ((buf)) { \
-                       efree((buf)); \
+                       pefree((buf), (persistent)); \
                        (buf) = NULL; \
                } \
                (buf_len) = 0; \
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_result.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_result.c
diff -u php-src/ext/mysqlnd/mysqlnd_result.c:1.2 
php-src/ext/mysqlnd/mysqlnd_result.c:1.3
--- php-src/ext/mysqlnd/mysqlnd_result.c:1.2    Fri Aug  3 16:32:26 2007
+++ php-src/ext/mysqlnd/mysqlnd_result.c        Mon Aug  6 15:11:46 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd_result.c,v 1.2 2007/08/03 16:32:26 andrey Exp $ */
+/* $Id: mysqlnd_result.c,v 1.3 2007/08/06 15:11:46 andrey Exp $ */
 #include "php.h"
 #include "mysqlnd.h"
 #include "mysqlnd_wireprotocol.h"
@@ -269,7 +269,8 @@
                                conn->upsert_status.affected_rows = 
rset_header.affected_rows;
                                conn->upsert_status.last_insert_id = 
rset_header.last_insert_id;
                                SET_NEW_MESSAGE(conn->last_message, 
conn->last_message_len,
-                                                               
rset_header.info_or_local_file, rset_header.info_or_local_file_len);
+                                                               
rset_header.info_or_local_file, rset_header.info_or_local_file_len,
+                                                               
conn->persistent);
                                /* Result set can follow UPSERT statement, 
check server_status */
                                if (conn->upsert_status.server_status & 
SERVER_MORE_RESULTS_EXISTS) {
                                        conn->state = CONN_NEXT_RESULT_PENDING;
@@ -284,7 +285,7 @@
                                MYSQLND_RES *result;
                                uint stat = -1;
 
-                               SET_EMPTY_MESSAGE(conn->last_message, 
conn->last_message_len);
+                               SET_EMPTY_MESSAGE(conn->last_message, 
conn->last_message_len, conn->persistent);
 
                                MYSQLND_INC_CONN_STATISTIC(&conn->stats, 
STAT_RSET_QUERY);
                                memset(&conn->upsert_status, 0, 
sizeof(conn->upsert_status));
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_statistics.h?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_statistics.h
diff -u php-src/ext/mysqlnd/mysqlnd_statistics.h:1.2 
php-src/ext/mysqlnd/mysqlnd_statistics.h:1.3
--- php-src/ext/mysqlnd/mysqlnd_statistics.h:1.2        Fri Aug  3 16:32:26 2007
+++ php-src/ext/mysqlnd/mysqlnd_statistics.h    Mon Aug  6 15:11:46 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mysqlnd_statistics.h,v 1.2 2007/08/03 16:32:26 andrey Exp $ */
+/* $Id: mysqlnd_statistics.h,v 1.3 2007/08/06 15:11:46 andrey Exp $ */
 
 #ifndef MYSQLND_STATISTICS_H
 #define MYSQLND_STATISTICS_H
@@ -100,7 +100,7 @@
  } 
 
 #define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, 
statistic2, value2, statistic3, value3) \
- { \                                                   \
+ { \
        if (mysqlnd_global_stats) { \
                my_uint64 v1 = (value1); \
                my_uint64 v2 = (value2); \
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_wireprotocol.c?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_wireprotocol.c
diff -u php-src/ext/mysqlnd/mysqlnd_wireprotocol.c:1.2 
php-src/ext/mysqlnd/mysqlnd_wireprotocol.c:1.3
--- php-src/ext/mysqlnd/mysqlnd_wireprotocol.c:1.2      Fri Aug  3 16:32:27 2007
+++ php-src/ext/mysqlnd/mysqlnd_wireprotocol.c  Mon Aug  6 15:11:46 2007
@@ -708,7 +708,7 @@
 
        /* There is a message */
        if (packet->header.size > p - buf && (i = 
php_mysqlnd_net_field_length(&p))) {
-               packet->message = estrndup((char *)p, MIN(i, sizeof(buf) - (p - 
buf)));
+               packet->message = pestrndup((char *)p, MIN(i, sizeof(buf) - (p 
- buf)), conn->persistent);
                packet->message_len = i;
        } else {
                packet->message = NULL;
@@ -906,7 +906,7 @@
                          Thus, the name is size - 1. And we add 1 for a 
trailing \0.
                        */
                        len = packet->header.size - 1;
-                       packet->info_or_local_file = emalloc(len + 1);
+                       packet->info_or_local_file = pemalloc(len + 1, 
conn->persistent);
                        memcpy(packet->info_or_local_file, p, len);
                        packet->info_or_local_file[len] = '\0';
                        packet->info_or_local_file_len = len;
@@ -920,7 +920,7 @@
                        p+=2;
                        /* Check for additional textual data */
                        if (packet->header.size  > (p - buf) && (len = 
php_mysqlnd_net_field_length(&p))) {
-                               packet->info_or_local_file = emalloc(len + 1);
+                               packet->info_or_local_file = pemalloc(len + 1, 
conn->persistent);
                                memcpy(packet->info_or_local_file, p, len);
                                packet->info_or_local_file[len] = '\0';
                                packet->info_or_local_file_len = len;
@@ -1574,7 +1574,7 @@
 
        PACKET_READ_HEADER_AND_BODY(packet, conn, buf, sizeof(buf), 
"statistics");
 
-       packet->message = emalloc(packet->header.size + 1);
+       packet->message = pemalloc(packet->header.size + 1, conn->persistent);
        memcpy(packet->message, buf, packet->header.size);
        packet->message[packet->header.size] = '\0';
        packet->message_len = packet->header.size;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to