mirror of
https://github.com/nginx/nginx.git
synced 2024-12-05 06:19:01 +08:00
fix segfault in "out of memory" situation
This commit is contained in:
parent
c690675ed1
commit
84bab05c55
@ -85,14 +85,17 @@ void *
|
|||||||
ngx_palloc(ngx_pool_t *pool, size_t size)
|
ngx_palloc(ngx_pool_t *pool, size_t size)
|
||||||
{
|
{
|
||||||
u_char *m;
|
u_char *m;
|
||||||
ngx_pool_t *p, *n;
|
ngx_pool_t *p, *n, *current;
|
||||||
ngx_pool_large_t *large;
|
ngx_pool_large_t *large;
|
||||||
|
|
||||||
if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL
|
if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL
|
||||||
&& size <= (size_t) (pool->end - (u_char *) pool)
|
&& size <= (size_t) (pool->end - (u_char *) pool)
|
||||||
- (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT))
|
- (size_t) ngx_align_ptr(sizeof(ngx_pool_t), NGX_ALIGNMENT))
|
||||||
{
|
{
|
||||||
for (p = pool->current; /* void */ ; p = p->next) {
|
p = pool->current;
|
||||||
|
current = p;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
|
||||||
if (size < sizeof(int) || (size & 1)) {
|
if (size < sizeof(int) || (size & 1)) {
|
||||||
m = p->last;
|
m = p->last;
|
||||||
@ -108,12 +111,15 @@ ngx_palloc(ngx_pool_t *pool, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((size_t) (p->end - m) < NGX_ALIGNMENT) {
|
if ((size_t) (p->end - m) < NGX_ALIGNMENT) {
|
||||||
pool->current = p->next;
|
current = p->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->next == NULL) {
|
if (p->next == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = p->next;
|
||||||
|
pool->current = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate a new pool block */
|
/* allocate a new pool block */
|
||||||
@ -123,9 +129,7 @@ ngx_palloc(ngx_pool_t *pool, size_t size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pool->current == NULL) {
|
pool->current = current ? current : n;
|
||||||
pool->current = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->next = n;
|
p->next = n;
|
||||||
m = ngx_align_ptr(n->last, NGX_ALIGNMENT);
|
m = ngx_align_ptr(n->last, NGX_ALIGNMENT);
|
||||||
|
Loading…
Reference in New Issue
Block a user