summaryrefslogtreecommitdiff
path: root/ext/mysql
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2010-05-25 22:55:10 (GMT)
committerAndrey Hristov <andrey@php.net>2010-05-25 22:55:10 (GMT)
commitf4f5a5075199e1e976301de1863ceda007b25b66 (patch)
tree44209ec27c08bf5cebdc73fb75c2334bd9ce691e /ext/mysql
parent1168cdc323af8955036f032c5f3e13cfe85f027b (diff)
downloadphp-f4f5a5075199e1e976301de1863ceda007b25b66.tar.gz
Handle the situation when mysql_init()/mysqlnd_init()
return NULL. It is a rare case of OOM but PHP shouldn't crash, if possible.
Diffstat (limited to 'ext/mysql')
-rw-r--r--ext/mysql/php_mysql.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c
index 7838df2..d63fe13 100644
--- a/ext/mysql/php_mysql.c
+++ b/ext/mysql/php_mysql.c
@@ -960,9 +960,17 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#else
mysql->conn = mysql_init(persistent);
#endif
+ if (!mysql->conn) {
+ MySG(connect_error) = estrdup("OOM");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "OOM");
+ efree(hashed_details);
+ efree(mysql);
+ MYSQL_DO_CONNECT_RETURN_FALSE();
+ }
- if (connect_timeout != -1)
- mysql_options(mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout);
+ 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)