From: Dmitry Volyntsev Date: Fri, 9 Oct 2026 22:59:52 +0000 (-0700) Subject: Modules: initialize shared dict state file before allocation X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=b543510147bc56166dc76bd583193dee34db7ac2;p=njs.git Modules: initialize shared dict state file before allocation Initialize the state file descriptor before allocating chain links and buffers. Allocation failures otherwise reach cleanup with an uninitialized descriptor and may close an unrelated file. --- diff --git a/nginx/ngx_js_shared_dict.c b/nginx/ngx_js_shared_dict.c index 49bf4a57..35631f2c 100644 --- a/nginx/ngx_js_shared_dict.c +++ b/nginx/ngx_js_shared_dict.c @@ -2609,6 +2609,11 @@ ngx_js_dict_save(ngx_js_dict_t *dict) name = dict->state_temp_file.data; + ngx_memzero(&file, sizeof(ngx_file_t)); + file.fd = NGX_INVALID_FILE; + file.name = dict->state_temp_file; + file.log = log; + out = NULL; ll = &out; @@ -2634,10 +2639,6 @@ ngx_js_dict_save(ngx_js_dict_t *dict) *ll = NULL; - ngx_memzero(&file, sizeof(ngx_file_t)); - file.name = dict->state_temp_file; - file.log = log; - file.fd = ngx_open_file(file.name.data, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE, NGX_FILE_DEFAULT_ACCESS);