allocate cf->conf_file and cf->conf_file->buffer on stack
Igor Sysoev
13 years ago
97 | 97 | char *rv; |
98 | 98 | ngx_fd_t fd; |
99 | 99 | ngx_int_t rc; |
100 | ngx_buf_t *b; | |
101 | ngx_conf_file_t *prev; | |
100 | ngx_buf_t buf; | |
101 | ngx_conf_file_t *prev, conf_file; | |
102 | 102 | enum { |
103 | 103 | parse_file = 0, |
104 | 104 | parse_block, |
124 | 124 | |
125 | 125 | prev = cf->conf_file; |
126 | 126 | |
127 | cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)); | |
128 | if (cf->conf_file == NULL) { | |
129 | return NGX_CONF_ERROR; | |
130 | } | |
127 | cf->conf_file = &conf_file; | |
131 | 128 | |
132 | 129 | if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { |
133 | 130 | ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
134 | 131 | ngx_fd_info_n " \"%s\" failed", filename->data); |
135 | 132 | } |
136 | 133 | |
137 | b = ngx_calloc_buf(cf->pool); | |
138 | if (b == NULL) { | |
139 | return NGX_CONF_ERROR; | |
140 | } | |
141 | ||
142 | cf->conf_file->buffer = b; | |
143 | ||
144 | b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log); | |
145 | if (b->start == NULL) { | |
146 | return NGX_CONF_ERROR; | |
147 | } | |
148 | ||
149 | b->pos = b->start; | |
150 | b->last = b->start; | |
151 | b->end = b->last + NGX_CONF_BUFFER; | |
152 | b->temporary = 1; | |
134 | cf->conf_file->buffer = &buf; | |
135 | ||
136 | buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log); | |
137 | if (buf.start == NULL) { | |
138 | goto failed; | |
139 | } | |
140 | ||
141 | buf.pos = buf.start; | |
142 | buf.last = buf.start; | |
143 | buf.end = buf.last + NGX_CONF_BUFFER; | |
144 | buf.temporary = 1; | |
153 | 145 | |
154 | 146 | cf->conf_file->file.fd = fd; |
155 | 147 | cf->conf_file->file.name.len = filename->len; |
255 | 247 | done: |
256 | 248 | |
257 | 249 | if (filename) { |
258 | ngx_free(cf->conf_file->buffer->start); | |
250 | if (cf->conf_file->buffer->start) { | |
251 | ngx_free(cf->conf_file->buffer->start); | |
252 | } | |
259 | 253 | |
260 | 254 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
261 | 255 | ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
833 | 827 | name->len = len + old.len; |
834 | 828 | name->data = ngx_pnalloc(cycle->pool, name->len + 1); |
835 | 829 | if (name->data == NULL) { |
836 | return NGX_ERROR; | |
830 | return NGX_ERROR; | |
837 | 831 | } |
838 | 832 | |
839 | 833 | p = ngx_cpymem(name->data, prefix, len); |