diff options
author | Andrey Hristov <andrey@php.net> | 2010-05-03 16:20:46 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2010-05-03 16:20:46 +0000 |
commit | f9fe805abecc95ea07c5e4bdab213e75db049cc5 (patch) | |
tree | df1908c83657b56049541173f8833b007f7754df /ext/mysqlnd/mysqlnd_block_alloc.c | |
parent | 864f2da7338c8a4f4b20facd74bc7f60f46afb76 (diff) | |
download | php-git-f9fe805abecc95ea07c5e4bdab213e75db049cc5.tar.gz |
Handle OOM in block_alloc_get_chunk, and also in the caller
in mysqlnd_wireprotocol.c
Diffstat (limited to 'ext/mysqlnd/mysqlnd_block_alloc.c')
-rw-r--r-- | ext/mysqlnd/mysqlnd_block_alloc.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/ext/mysqlnd/mysqlnd_block_alloc.c b/ext/mysqlnd/mysqlnd_block_alloc.c index 47b4c4af66..5d618d145e 100644 --- a/ext/mysqlnd/mysqlnd_block_alloc.c +++ b/ext/mysqlnd/mysqlnd_block_alloc.c @@ -119,29 +119,30 @@ MYSQLND_MEMORY_POOL_CHUNK * mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool 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); } |