Author: ahristov
Date: 2007-08-06 15:19:30 +0200 (Mon, 06 Aug 2007)
New Revision: 855
Modified:
trunk/mysqlnd/mysqlnd.c
trunk/mysqlnd/mysqlnd_priv.h
trunk/mysqlnd/mysqlnd_result.c
trunk/mysqlnd/mysqlnd_wireprotocol.c
trunk/php4/ext/mysql/php_mysql.c
trunk/php5/ext/mysql/php_mysql.c
trunk/php6/ext/mysql/php_mysql.c
Log:
Fix crashes with persistent connections. Can't be tested with
CLI :( . Memory got allocated with emalloc, but the connection
handle survived. Probably zend complained about non-freed memory.
On the next script run we tried to use already freed memory - boom.
Modified: trunk/mysqlnd/mysqlnd.c
===================================================================
--- trunk/mysqlnd/mysqlnd.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/mysqlnd/mysqlnd.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -262,7 +262,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;
@@ -388,6 +389,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;
+ }
}
/* }}} */
@@ -612,7 +618,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);
Modified: trunk/mysqlnd/mysqlnd_priv.h
===================================================================
--- trunk/mysqlnd/mysqlnd_priv.h 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/mysqlnd/mysqlnd_priv.h 2007-08-06 13:19:30 UTC (rev 855)
@@ -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; \
Modified: trunk/mysqlnd/mysqlnd_result.c
===================================================================
--- trunk/mysqlnd/mysqlnd_result.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/mysqlnd/mysqlnd_result.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -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));
Modified: trunk/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- trunk/mysqlnd/mysqlnd_wireprotocol.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/mysqlnd/mysqlnd_wireprotocol.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -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;
Modified: trunk/php4/ext/mysql/php_mysql.c
===================================================================
--- trunk/php4/ext/mysql/php_mysql.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/php4/ext/mysql/php_mysql.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -842,6 +842,10 @@
}
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);
Modified: trunk/php5/ext/mysql/php_mysql.c
===================================================================
--- trunk/php5/ext/mysql/php_mysql.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/php5/ext/mysql/php_mysql.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -772,6 +772,10 @@
}
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);
Modified: trunk/php6/ext/mysql/php_mysql.c
===================================================================
--- trunk/php6/ext/mysql/php_mysql.c 2007-08-06 11:50:39 UTC (rev 854)
+++ trunk/php6/ext/mysql/php_mysql.c 2007-08-06 13:19:30 UTC (rev 855)
@@ -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);
| Thread |
|---|
| • PHP mysqlnd svn commit: r855 - in trunk: mysqlnd php4/ext/mysql php5/ext/mysql php6/ext/mysql | ahristov | 6 Aug |