Mercurial > hg > nginx
comparison src/core/ngx_alloc.c @ 194:2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 21 Nov 2003 06:30:49 +0000 |
parents | afc333135a6b |
children | 70e1c7d2b83d |
comparison
equal
deleted
inserted
replaced
193:dd66383796a5 | 194:2357fa41738a |
---|---|
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 | 4 |
5 | 5 |
6 void *ngx_alloc(size_t size, ngx_log_t *log) | 6 void *ngx_alloc(size_t size, ngx_log_t *log) |
7 { | 7 { |
8 void *p; | 8 void *p; |
9 | 9 |
10 p = malloc(size); | 10 if (!(p = malloc(size))) { |
11 if (p == NULL) { | |
12 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 11 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
13 "malloc() %d bytes failed", size); | 12 "malloc() %d bytes failed", size); |
14 } | 13 } |
15 | 14 |
16 #if (NGX_DEBUG_ALLOC) | 15 #if (NGX_DEBUG_ALLOC) |
21 } | 20 } |
22 | 21 |
23 | 22 |
24 void *ngx_calloc(size_t size, ngx_log_t *log) | 23 void *ngx_calloc(size_t size, ngx_log_t *log) |
25 { | 24 { |
26 void *p; | 25 void *p; |
27 | 26 |
28 p = ngx_alloc(size, log); | 27 p = ngx_alloc(size, log); |
29 if (p) { | 28 if (p) { |
30 ngx_memzero(p, size); | 29 ngx_memzero(p, size); |
31 } | 30 } |
34 } | 33 } |
35 | 34 |
36 | 35 |
37 ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log) | 36 ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log) |
38 { | 37 { |
39 ngx_pool_t *p; | 38 ngx_pool_t *p; |
40 | 39 |
41 ngx_test_null(p, ngx_alloc(size, log), NULL); | 40 if (!(p = ngx_alloc(size, log))) { |
41 return NULL; | |
42 } | |
42 | 43 |
43 p->last = (char *) p + sizeof(ngx_pool_t); | 44 p->last = (char *) p + sizeof(ngx_pool_t); |
44 p->end = (char *) p + size; | 45 p->end = (char *) p + size; |
45 p->next = NULL; | 46 p->next = NULL; |
46 p->large = NULL; | 47 p->large = NULL; |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 /* alloc a new pool block */ | 117 /* alloc a new pool block */ |
117 | 118 |
118 ngx_test_null(n, ngx_create_pool(p->end - (char *) p, p->log), NULL); | 119 if (!(n = ngx_create_pool((size_t) (p->end - (char *) p), p->log))) { |
120 return NULL; | |
121 } | |
122 | |
119 p->next = n; | 123 p->next = n; |
120 m = n->last; | 124 m = n->last; |
121 n->last += size; | 125 n->last += size; |
122 | 126 |
123 return m; | 127 return m; |
141 } | 145 } |
142 } | 146 } |
143 } | 147 } |
144 | 148 |
145 if (large == NULL) { | 149 if (large == NULL) { |
146 ngx_test_null(large, ngx_palloc(pool, sizeof(ngx_pool_large_t)), NULL); | 150 if (!(large = ngx_palloc(pool, sizeof(ngx_pool_large_t)))) { |
151 return NULL; | |
152 } | |
153 | |
147 large->next = NULL; | 154 large->next = NULL; |
148 } | 155 } |
149 | 156 |
150 ngx_test_null(p, ngx_alloc(size, pool->log), NULL); | 157 if (!(p = ngx_alloc(size, pool->log))) { |
158 return NULL; | |
159 } | |
151 | 160 |
152 if (pool->large == NULL) { | 161 if (pool->large == NULL) { |
153 pool->large = large; | 162 pool->large = large; |
154 | 163 |
155 } else if (last) { | 164 } else if (last) { |