From 157e5d47b5326b27064955d30a694daf8f3b12cd Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Thu, 23 Nov 2023 03:04:02 -0500 Subject: [PATCH] util.c: Don't leak directory handle if recursive call to dirRemove fails (#12800) If a recursive call to dirRemove() returns -1, dirRemove() the directory handle stored in dir will leak. This change closes the directory handle stored in dir even if the recursive call to dirRemove() returns -1. Fixed Coverity 371073 --- src/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.c b/src/util.c index 17aabf648..e5e01fe76 100644 --- a/src/util.c +++ b/src/util.c @@ -1061,6 +1061,7 @@ int dirRemove(char *dname) { if (S_ISDIR(stat_entry.st_mode) != 0) { if (dirRemove(full_path) == -1) { + closedir(dir); return -1; } continue;