]> git.kaiwu.me - njs.git/commitdiff
Fixed closing file descriptor on error.
authorRoman Arutyunyan <arut@nginx.com>
Thu, 21 Jul 2016 08:39:00 +0000 (11:39 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Thu, 21 Jul 2016 08:39:00 +0000 (11:39 +0300)
Found by Coverity (CID 1364196136419713641981364199).

nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c

index 47ac83d96c68c32673c4114ae9b9b85c490af132..f8ad1f27619b99d878c022591b5ef5ebe320de7c 100644 (file)
@@ -1249,6 +1249,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     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_command_t *cmd, void *conf)
 
     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_command_t *cmd, void *conf)
         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_command_t *cmd, void *conf)
                       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;
     }
 
index 62273ce0999323ebc3eaae65483ee5ba2866229a..53dfed261e1d380b921743a5d8d947afe139c1c7 100644 (file)
@@ -456,6 +456,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     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, ngx_command_t *cmd, void *conf)
 
     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, ngx_command_t *cmd, void *conf)
         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;
     }