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
This commit is contained in:
Moshe Kaplan 2023-11-23 03:04:02 -05:00 committed by GitHub
parent 463476933c
commit 157e5d47b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;