Resolver: allocate resolver from configuration pool.
Before 4a8c9139e579, ngx_resolver_create() didn't use configuration pool, and allocations were done using malloc(). In 016352c19049, when resolver gained support of several servers, new allocations were done from the pool.
This commit is contained in:
parent
0553c81ea1
commit
1f5b38eff9
1 changed files with 34 additions and 45 deletions
|
@ -141,25 +141,24 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n)
|
|||
ngx_pool_cleanup_t *cln;
|
||||
ngx_resolver_connection_t *rec;
|
||||
|
||||
r = ngx_pcalloc(cf->pool, sizeof(ngx_resolver_t));
|
||||
if (r == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t));
|
||||
if (r->event == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cln = ngx_pool_cleanup_add(cf->pool, 0);
|
||||
if (cln == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cln->handler = ngx_resolver_cleanup;
|
||||
|
||||
r = ngx_calloc(sizeof(ngx_resolver_t), cf->log);
|
||||
if (r == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cln->data = r;
|
||||
|
||||
r->event = ngx_calloc(sizeof(ngx_event_t), cf->log);
|
||||
if (r->event == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ngx_rbtree_init(&r->name_rbtree, &r->name_sentinel,
|
||||
ngx_resolver_rbtree_insert_value);
|
||||
|
||||
|
@ -288,9 +287,7 @@ ngx_resolver_cleanup(void *data)
|
|||
ngx_uint_t i;
|
||||
ngx_resolver_connection_t *rec;
|
||||
|
||||
if (r) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
|
||||
"cleanup resolver");
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "cleanup resolver");
|
||||
|
||||
ngx_resolver_cleanup_tree(r, &r->name_rbtree);
|
||||
|
||||
|
@ -302,15 +299,10 @@ ngx_resolver_cleanup(void *data)
|
|||
ngx_resolver_cleanup_tree(r, &r->addr6_rbtree);
|
||||
#endif
|
||||
|
||||
if (r->event) {
|
||||
if (r->event->timer_set) {
|
||||
ngx_del_timer(r->event);
|
||||
}
|
||||
|
||||
ngx_free(r->event);
|
||||
}
|
||||
|
||||
|
||||
rec = r->connections.elts;
|
||||
|
||||
for (i = 0; i < r->connections.nelts; i++) {
|
||||
|
@ -332,9 +324,6 @@ ngx_resolver_cleanup(void *data)
|
|||
ngx_resolver_free(r, rec[i].write_buf);
|
||||
}
|
||||
}
|
||||
|
||||
ngx_free(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue