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:
Ruslan Ermilov 2018-06-13 22:37:42 +03:00
parent 9b6bc8a578
commit 4542898917

View File

@ -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,52 +287,42 @@ 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);
ngx_resolver_cleanup_tree(r, &r->name_rbtree);
ngx_resolver_cleanup_tree(r, &r->srv_rbtree);
ngx_resolver_cleanup_tree(r, &r->srv_rbtree);
ngx_resolver_cleanup_tree(r, &r->addr_rbtree);
ngx_resolver_cleanup_tree(r, &r->addr_rbtree);
#if (NGX_HAVE_INET6)
ngx_resolver_cleanup_tree(r, &r->addr6_rbtree);
ngx_resolver_cleanup_tree(r, &r->addr6_rbtree);
#endif
if (r->event) {
if (r->event->timer_set) {
ngx_del_timer(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++) {
if (rec[i].udp) {
ngx_close_connection(rec[i].udp);
}
rec = r->connections.elts;
for (i = 0; i < r->connections.nelts; i++) {
if (rec[i].udp) {
ngx_close_connection(rec[i].udp);
}
if (rec[i].tcp) {
ngx_close_connection(rec[i].tcp);
}
if (rec[i].read_buf) {
ngx_resolver_free(r, rec[i].read_buf->start);
ngx_resolver_free(r, rec[i].read_buf);
}
if (rec[i].write_buf) {
ngx_resolver_free(r, rec[i].write_buf->start);
ngx_resolver_free(r, rec[i].write_buf);
}
if (rec[i].tcp) {
ngx_close_connection(rec[i].tcp);
}
ngx_free(r);
if (rec[i].read_buf) {
ngx_resolver_free(r, rec[i].read_buf->start);
ngx_resolver_free(r, rec[i].read_buf);
}
if (rec[i].write_buf) {
ngx_resolver_free(r, rec[i].write_buf->start);
ngx_resolver_free(r, rec[i].write_buf);
}
}
}