andrey                                   Mon, 03 May 2010 16:20:46 +0000

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

Log:
Handle OOM in block_alloc_get_chunk, and also in the caller
in mysqlnd_wireprotocol.c

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

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_block_alloc.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_block_alloc.c      
2010-05-03 16:09:05 UTC (rev 298910)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_block_alloc.c      
2010-05-03 16:20:46 UTC (rev 298911)
@@ -119,29 +119,30 @@
        DBG_ENTER("mysqlnd_mempool_get_chunk");

        chunk = mnd_malloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
-
-       chunk->free_chunk = mysqlnd_mempool_free_chunk;
-       chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
-       chunk->size = size;
-       /*
-         Should not go over MYSQLND_MAX_PACKET_SIZE, since we
-         expect non-arena memory in mysqlnd_wireprotocol.c . We
-         realloc the non-arena memory.
-       */
-       chunk->pool = pool;
-       if (size > pool->free_size) {
-               chunk->from_pool = FALSE;
-               chunk->ptr = mnd_malloc(size);
-               if (!chunk->ptr) {
-                       chunk->free_chunk(chunk TSRMLS_CC);
-                       chunk = NULL;
+       if (chunk) {
+               chunk->free_chunk = mysqlnd_mempool_free_chunk;
+               chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
+               chunk->size = size;
+               /*
+                 Should not go over MYSQLND_MAX_PACKET_SIZE, since we
+                 expect non-arena memory in mysqlnd_wireprotocol.c . We
+                 realloc the non-arena memory.
+               */
+               chunk->pool = pool;
+               if (size > pool->free_size) {
+                       chunk->from_pool = FALSE;
+                       chunk->ptr = mnd_malloc(size);
+                       if (!chunk->ptr) {
+                               chunk->free_chunk(chunk TSRMLS_CC);
+                               chunk = NULL;
+                       }
+               } else {
+                       chunk->from_pool = TRUE;
+                       ++pool->refcount;
+                       chunk->ptr = pool->arena + (pool->arena_size - 
pool->free_size);
+                       /* Last step, update free_size */
+                       pool->free_size -= size;
                }
-       } else {
-               chunk->from_pool = TRUE;
-               ++pool->refcount;
-               chunk->ptr = pool->arena + (pool->arena_size - pool->free_size);
-               /* Last step, update free_size */
-               pool->free_size -= size;
        }
        DBG_RETURN(chunk);
 }

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c     
2010-05-03 16:09:05 UTC (rev 298910)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c     
2010-05-03 16:20:46 UTC (rev 298911)
@@ -1136,6 +1136,10 @@
                          to be able to implement read-only variables. Thus, we 
add + 1.
                        */
                        *buffer = 
result_set_memory_pool->get_chunk(result_set_memory_pool, *data_size + 1 
TSRMLS_CC);
+                       if (!*buffer) {
+                               ret = FAIL;
+                               break;
+                       }
                        p = (*buffer)->ptr;
                } else if (!first_iteration) {
                        /* Empty packet after MYSQLND_MAX_PACKET_SIZE packet. 
That's ok, break */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_block_alloc.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_block_alloc.c 2010-05-03 16:09:05 UTC 
(rev 298910)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_block_alloc.c 2010-05-03 16:20:46 UTC 
(rev 298911)
@@ -119,29 +119,30 @@
        DBG_ENTER("mysqlnd_mempool_get_chunk");

        chunk = mnd_malloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
-
-       chunk->free_chunk = mysqlnd_mempool_free_chunk;
-       chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
-       chunk->size = size;
-       /*
-         Should not go over MYSQLND_MAX_PACKET_SIZE, since we
-         expect non-arena memory in mysqlnd_wireprotocol.c . We
-         realloc the non-arena memory.
-       */
-       chunk->pool = pool;
-       if (size > pool->free_size) {
-               chunk->from_pool = FALSE;
-               chunk->ptr = mnd_malloc(size);
-               if (!chunk->ptr) {
-                       chunk->free_chunk(chunk TSRMLS_CC);
-                       chunk = NULL;
+       if (chunk) {
+               chunk->free_chunk = mysqlnd_mempool_free_chunk;
+               chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
+               chunk->size = size;
+               /*
+                 Should not go over MYSQLND_MAX_PACKET_SIZE, since we
+                 expect non-arena memory in mysqlnd_wireprotocol.c . We
+                 realloc the non-arena memory.
+               */
+               chunk->pool = pool;
+               if (size > pool->free_size) {
+                       chunk->from_pool = FALSE;
+                       chunk->ptr = mnd_malloc(size);
+                       if (!chunk->ptr) {
+                               chunk->free_chunk(chunk TSRMLS_CC);
+                               chunk = NULL;
+                       }
+               } else {
+                       chunk->from_pool = TRUE;
+                       ++pool->refcount;
+                       chunk->ptr = pool->arena + (pool->arena_size - 
pool->free_size);
+                       /* Last step, update free_size */
+                       pool->free_size -= size;
                }
-       } else {
-               chunk->from_pool = TRUE;
-               ++pool->refcount;
-               chunk->ptr = pool->arena + (pool->arena_size - pool->free_size);
-               /* Last step, update free_size */
-               pool->free_size -= size;
        }
        DBG_RETURN(chunk);
 }

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c        2010-05-03 
16:09:05 UTC (rev 298910)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c        2010-05-03 
16:20:46 UTC (rev 298911)
@@ -1136,6 +1136,10 @@
                          to be able to implement read-only variables. Thus, we 
add + 1.
                        */
                        *buffer = 
result_set_memory_pool->get_chunk(result_set_memory_pool, *data_size + 1 
TSRMLS_CC);
+                       if (!*buffer) {
+                               ret = FAIL;
+                               break;
+                       }
                        p = (*buffer)->ptr;
                } else if (!first_iteration) {
                        /* Empty packet after MYSQLND_MAX_PACKET_SIZE packet. 
That's ok, break */

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

Reply via email to