comparison src/core/ngx_conf_file.c @ 2339:2142237f66da

allocate cf->conf_file and cf->conf_file->buffer on stack
author Igor Sysoev <igor@sysoev.ru>
date Tue, 25 Nov 2008 15:55:10 +0000
parents 5cbf2da3a324
children a6d6d762c554
comparison
equal deleted inserted replaced
2338:5cbf2da3a324 2339:2142237f66da
96 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 96 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
97 { 97 {
98 char *rv; 98 char *rv;
99 ngx_fd_t fd; 99 ngx_fd_t fd;
100 ngx_int_t rc; 100 ngx_int_t rc;
101 ngx_buf_t *b; 101 ngx_buf_t buf;
102 ngx_conf_file_t *prev; 102 ngx_conf_file_t *prev, conf_file;
103 enum { 103 enum {
104 parse_file = 0, 104 parse_file = 0,
105 parse_block, 105 parse_block,
106 parse_param 106 parse_param
107 } type; 107 } type;
123 return NGX_CONF_ERROR; 123 return NGX_CONF_ERROR;
124 } 124 }
125 125
126 prev = cf->conf_file; 126 prev = cf->conf_file;
127 127
128 cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)); 128 cf->conf_file = &conf_file;
129 if (cf->conf_file == NULL) {
130 return NGX_CONF_ERROR;
131 }
132 129
133 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { 130 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
134 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, 131 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
135 ngx_fd_info_n " \"%s\" failed", filename->data); 132 ngx_fd_info_n " \"%s\" failed", filename->data);
136 } 133 }
137 134
138 b = ngx_calloc_buf(cf->pool); 135 cf->conf_file->buffer = &buf;
139 if (b == NULL) { 136
140 return NGX_CONF_ERROR; 137 buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
141 } 138 if (buf.start == NULL) {
142 139 goto failed;
143 cf->conf_file->buffer = b; 140 }
144 141
145 b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log); 142 buf.pos = buf.start;
146 if (b->start == NULL) { 143 buf.last = buf.start;
147 return NGX_CONF_ERROR; 144 buf.end = buf.last + NGX_CONF_BUFFER;
148 } 145 buf.temporary = 1;
149
150 b->pos = b->start;
151 b->last = b->start;
152 b->end = b->last + NGX_CONF_BUFFER;
153 b->temporary = 1;
154 146
155 cf->conf_file->file.fd = fd; 147 cf->conf_file->file.fd = fd;
156 cf->conf_file->file.name.len = filename->len; 148 cf->conf_file->file.name.len = filename->len;
157 cf->conf_file->file.name.data = filename->data; 149 cf->conf_file->file.name.data = filename->data;
158 cf->conf_file->file.offset = 0; 150 cf->conf_file->file.offset = 0;
254 rc = NGX_ERROR; 246 rc = NGX_ERROR;
255 247
256 done: 248 done:
257 249
258 if (filename) { 250 if (filename) {
259 ngx_free(cf->conf_file->buffer->start); 251 if (cf->conf_file->buffer->start) {
252 ngx_free(cf->conf_file->buffer->start);
253 }
260 254
261 if (ngx_close_file(fd) == NGX_FILE_ERROR) { 255 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
262 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, 256 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
263 ngx_close_file_n " %s failed", 257 ngx_close_file_n " %s failed",
264 cf->conf_file->file.name.data); 258 cf->conf_file->file.name.data);
832 } 826 }
833 827
834 name->len = len + old.len; 828 name->len = len + old.len;
835 name->data = ngx_pnalloc(cycle->pool, name->len + 1); 829 name->data = ngx_pnalloc(cycle->pool, name->len + 1);
836 if (name->data == NULL) { 830 if (name->data == NULL) {
837 return NGX_ERROR; 831 return NGX_ERROR;
838 } 832 }
839 833
840 p = ngx_cpymem(name->data, prefix, len); 834 p = ngx_cpymem(name->data, prefix, len);
841 ngx_cpystrn(p, old.data, old.len + 1); 835 ngx_cpystrn(p, old.data, old.len + 1);
842 836