summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2010-05-25 22:42:25 (GMT)
committerAndrey Hristov <andrey@php.net>2010-05-25 22:42:25 (GMT)
commit708b31a5108d9b1b5c6bec340ce0110a18cbbdde (patch)
tree8e697cab7d355ed0a7904d8ee2e4d33309280bf1 /ext
parent6d434e70a4659dc2579f224ebc7ab96d8aa6327f (diff)
downloadphp-708b31a5108d9b1b5c6bec340ce0110a18cbbdde.tar.gz
Gracefully handle OOM in mysqlnd_stmt_init. Release the handle
and return NULL.
Diffstat (limited to 'ext')
-rw-r--r--ext/mysqlnd/mysqlnd_ps.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c
index db50bbc..41ec5e6 100644
--- a/ext/mysqlnd/mysqlnd_ps.c
+++ b/ext/mysqlnd/mysqlnd_ps.c
@@ -2194,25 +2194,45 @@ MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
{
size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
- MYSQLND_STMT_DATA * stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
+ MYSQLND_STMT_DATA * stmt = NULL;
DBG_ENTER("_mysqlnd_stmt_init");
- DBG_INF_FMT("stmt=%p", stmt);
+ do {
+ if (!ret) {
+ break;
+ }
+ ret->m = mysqlnd_stmt_methods;
- ret->m = mysqlnd_stmt_methods;
- stmt->persistent = conn->persistent;
- stmt->state = MYSQLND_STMT_INITTED;
- stmt->execute_cmd_buffer.length = 4096;
- stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
+ stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
+ DBG_INF_FMT("stmt=%p", stmt);
+ if (!stmt) {
+ break;
+ }
+ stmt->persistent = conn->persistent;
+ stmt->state = MYSQLND_STMT_INITTED;
+ stmt->execute_cmd_buffer.length = 4096;
+ stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
+ if (!stmt->execute_cmd_buffer.buffer) {
+ break;
+ }
- stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
- /*
- Mark that we reference the connection, thus it won't be
- be destructed till there is open statements. The last statement
- or normal query result will close it then.
- */
- stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
- DBG_RETURN(ret);
+ stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
+ /*
+ Mark that we reference the connection, thus it won't be
+ be destructed till there is open statements. The last statement
+ or normal query result will close it then.
+ */
+ stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
+
+ DBG_RETURN(ret);
+ } while (0);
+
+ SET_OOM_ERROR(conn->error_info);
+ if (ret) {
+ ret->m->dtor(ret, TRUE TSRMLS_CC);
+ ret = NULL;
+ }
+ DBG_RETURN(NULL);
}
/* }}} */