[nginx] Resolver: allocate resolver from configuration pool.
Ruslan Ermilov
ru at nginx.com
Thu Jun 14 03:29:40 UTC 2018
details: http://hg.nginx.org/nginx/rev/f37d8fb25de5
branches:
changeset: 7298:f37d8fb25de5
user: Ruslan Ermilov <ru at nginx.com>
date: Wed Jun 13 22:37:42 2018 +0300
description:
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.
diffstat:
src/core/ngx_resolver.c | 87 +++++++++++++++++++++---------------------------
1 files changed, 38 insertions(+), 49 deletions(-)
diffs (120 lines):
diff -r a10e5fe44762 -r f37d8fb25de5 src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c Wed Jun 13 15:28:11 2018 +0300
+++ b/src/core/ngx_resolver.c Wed Jun 13 22:37:42 2018 +0300
@@ -141,25 +141,24 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
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_resolver_cleanup_tree(r, &r->name_rbtree);
-
- ngx_resolver_cleanup_tree(r, &r->srv_rbtree);
-
- ngx_resolver_cleanup_tree(r, &r->addr_rbtree);
+ 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->srv_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);
- }
-
- ngx_free(r->event);
+ if (r->event->timer_set) {
+ ngx_del_timer(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);
+ }
}
}
More information about the nginx-devel
mailing list