[njs] Fixed closing file descriptor on error.

Roman Arutyunyan arut at nginx.com
Thu Jul 21 10:33:03 UTC 2016


details:   http://hg.nginx.org/njs/rev/1cfc38ab7ba1
branches:  
changeset: 127:1cfc38ab7ba1
user:      Roman Arutyunyan <arut at nginx.com>
date:      Thu Jul 21 11:39:00 2016 +0300
description:
Fixed closing file descriptor on error.

Found by Coverity (CID 1364196, 1364197, 1364198, 1364199).

diffstat:

 nginx/ngx_http_js_module.c   |  6 ++++--
 nginx/ngx_stream_js_module.c |  8 +++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diffs (76 lines):

diff -r faab537db6f8 -r 1cfc38ab7ba1 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Wed Jul 20 21:40:34 2016 +0300
+++ b/nginx/ngx_http_js_module.c	Thu Jul 21 11:39:00 2016 +0300
@@ -1249,6 +1249,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
     if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
         ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
                       ngx_fd_info_n " \"%s\" failed", file.data);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
@@ -1256,6 +1257,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
 
     start = ngx_pnalloc(cf->pool, size);
     if (start == NULL) {
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
@@ -1265,7 +1267,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
         ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
                       ngx_read_fd_n " \"%s\" failed", file.data);
 
-        ngx_close_file(fd);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
@@ -1274,7 +1276,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
                       ngx_read_fd_n " has read only %z of %O from \"%s\"",
                       n, size, file.data);
 
-        ngx_close_file(fd);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
diff -r faab537db6f8 -r 1cfc38ab7ba1 nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Wed Jul 20 21:40:34 2016 +0300
+++ b/nginx/ngx_stream_js_module.c	Thu Jul 21 11:39:00 2016 +0300
@@ -456,6 +456,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng
     if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
         ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
                       ngx_fd_info_n " \"%s\" failed", file.data);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
@@ -463,6 +464,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng
 
     start = ngx_pnalloc(cf->pool, size);
     if (start == NULL) {
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
@@ -472,16 +474,16 @@ ngx_stream_js_include(ngx_conf_t *cf, ng
         ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
                       ngx_read_fd_n " \"%s\" failed", file.data);
 
-        ngx_close_file(fd);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 
     if ((size_t) n != size) {
         ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
-                      ngx_read_fd_n " has read only %z of %O from \"%s\"",
+                      ngx_read_fd_n " has read only %z of %uz from \"%s\"",
                       n, size, file.data);
 
-        ngx_close_file(fd);
+        (void) ngx_close_file(fd);
         return NGX_CONF_ERROR;
     }
 



More information about the nginx-devel mailing list