andrey                                   Tue, 25 May 2010 22:42:25 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299762

Log:
Gracefully handle OOM in mysqlnd_stmt_init. Release the handle
and return NULL.

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c       2010-05-25 
22:40:47 UTC (rev 299761)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c       2010-05-25 
22:42:25 UTC (rev 299762)
@@ -2194,25 +2194,45 @@
 {
        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);
 }
 /* }}} */


Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c  2010-05-25 22:40:47 UTC (rev 
299761)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c  2010-05-25 22:42:25 UTC (rev 
299762)
@@ -2194,25 +2194,45 @@
 {
        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);
 }
 /* }}} */


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

Reply via email to