[njs] Fixing Coverity warnings introduced in 24de499877ca.

Dmitry Volyntsev xeioex at nginx.com
Wed Aug 12 15:02:08 UTC 2020


details:   https://hg.nginx.org/njs/rev/5cce5069440e
branches:  
changeset: 1491:5cce5069440e
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Aug 12 14:57:31 2020 +0000
description:
Fixing Coverity warnings introduced in 24de499877ca.

CIDs: 1465870, 1465871, 1465872.

diffstat:

 src/njs_fs.c |  31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diffs (65 lines):

diff -r 7711232339a1 -r 5cce5069440e src/njs_fs.c
--- a/src/njs_fs.c	Wed Aug 12 12:56:35 2020 +0000
+++ b/src/njs_fs.c	Wed Aug 12 14:57:31 2020 +0000
@@ -1292,6 +1292,12 @@ njs_ftw(char *path, njs_file_tree_walk_c
         return 0;
     }
 
+    for (h = parent; h != NULL; h = h->chain) {
+        if (h->dev == st.st_dev && h->ino == st.st_ino) {
+            return 0;
+        }
+    }
+
     len = njs_strlen(path);
     base = len && (path[len - 1] == '/') ? len - 1 : len;
 
@@ -1305,28 +1311,27 @@ njs_ftw(char *path, njs_file_tree_walk_c
     if (type == NJS_FTW_D || type == NJS_FTW_DP) {
         dfd = open(path, O_RDONLY);
         err = errno;
-        if (dfd < 0 && err == EACCES) {
-            type = NJS_FTW_DNR;
-        }
-
-        if (fd_limit == 0) {
-            close(dfd);
+        if (dfd < 0) {
+            if (err == EACCES) {
+                type = NJS_FTW_DNR;
+            }
+
+        } else if (fd_limit == 0) {
+            (void) close(dfd);
         }
     }
 
     if (!(flags & NJS_FTW_DEPTH)) {
         ret = cb(path, &st, type);
         if (njs_slow_path(ret != 0)) {
+            if (dfd >= 0) {
+                (void) close(dfd);
+            }
+
             return ret;
         }
     }
 
-    for (h = parent; h != NULL; h = h->chain) {
-        if (h->dev == st.st_dev && h->ino == st.st_ino) {
-            return 0;
-        }
-    }
-
     if ((type == NJS_FTW_D || type == NJS_FTW_DP) && fd_limit != 0) {
         if (dfd < 0) {
             errno = err;
@@ -1335,7 +1340,7 @@ njs_ftw(char *path, njs_file_tree_walk_c
 
         d = fdopendir(dfd);
         if (njs_slow_path(d == NULL)) {
-            close(dfd);
+            (void) close(dfd);
             return -1;
         }
 


More information about the nginx-devel mailing list