diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-07-12 20:32:19 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-07-12 20:32:19 +0300 |
commit | 7d3fd1c96ca91a311b21cbaefc947f430f2130b9 (patch) | |
tree | dcf3ae0769fc51b0bbdb285281a882248769f607 /src/nxt_router.c | |
parent | a97a5e8a0b7a921905994bae101d4f74f5a8aaa4 (diff) | |
download | unit-7d3fd1c96ca91a311b21cbaefc947f430f2130b9.tar.gz unit-7d3fd1c96ca91a311b21cbaefc947f430f2130b9.tar.bz2 |
Single allocation for app conf and name.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_router.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c index fa43b09f..b4a8e82d 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -531,28 +531,28 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_debug(task, "application \"%V\"", &name); - app = nxt_zalloc(sizeof(nxt_app_t)); + size = nxt_conf_json_length(application, NULL); + + app = nxt_malloc(sizeof(nxt_app_t) + name.length + size); if (app == NULL) { goto fail; } - size = nxt_conf_json_length(application, NULL); + nxt_memzero(app, sizeof(nxt_app_t)); - app->conf.start = nxt_malloc(size); - if (app->conf.start == NULL) { - nxt_free(app); - goto fail; - } + app->name.start = nxt_pointer_to(app, sizeof(nxt_app_t)); + app->conf.start = nxt_pointer_to(app, sizeof(nxt_app_t) + name.length); p = nxt_conf_json_print(app->conf.start, application, NULL); app->conf.length = p - app->conf.start; + nxt_assert(app->conf.length <= size); + nxt_debug(task, "application conf \"%V\"", &app->conf); prev = nxt_router_app_find(&tmcf->conf->router->apps, &name); if (prev != NULL && nxt_strstr_eq(&app->conf, &prev->conf)) { - nxt_free(app->conf.start); nxt_free(app); nxt_queue_remove(&prev->link); @@ -592,7 +592,9 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_queue_init(&app->ports); nxt_queue_init(&app->requests); - app->name = name; + app->name.length = name.length; + nxt_memcpy(app->name.start, name.start, name.length); + app->type = type; app->max_workers = apcf.workers; app->live = 1; @@ -676,7 +678,6 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, app_fail: - nxt_free(app->conf.start); nxt_free(app); fail: @@ -1192,6 +1193,10 @@ nxt_router_apps_sort(nxt_router_t *router, nxt_router_temp_conf_t *tmcf) nxt_queue_remove(&app->link); // TODO RELEASE APP +#if 0 + nxt_thread_mutex_destroy(&app->mutex); + nxt_free(app); +#endif } nxt_queue_loop; nxt_queue_add(&router->apps, &tmcf->previous); |