From df1cb0d70cfd46cef3156ac38d0b5d802ec16418 Mon Sep 17 00:00:00 2001 From: remoof Date: Sat, 17 Jul 2021 15:54:39 +0200 Subject: [PATCH] Avoid closing on bad file descriptors --- sessions.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sessions.h b/sessions.h index 13c4fc3..19cf679 100644 --- a/sessions.h +++ b/sessions.h @@ -14,10 +14,8 @@ int getpstartts(int pid, unsigned long long* startts) { snprintf(path, sizeof(path), "/proc/%d/stat", pid); int fd = open(path, O_RDONLY); - if (fd < 0) { - close(fd); + if (fd < 0) err(1, "Could not open %s", path); - } int bytes_read = read(fd, fc, sizeof(fc)); @@ -57,7 +55,6 @@ int ensuredir(int recur) { int fd = open("/run/rdo", O_RDONLY, O_DIRECTORY | O_NOFOLLOW); if (fd < 0) { - close(fd); if (errno == ENOENT) { if (mkdir("/run/rdo", 0700) < 0) err(1, "Could not create /run/rdo"); @@ -94,7 +91,6 @@ void setsession(int pid, unsigned int ts_ttl) { int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0700); if (fd < 0) { - close(fd); if (errno == EEXIST) return; err(1, "Could not open %s", path); @@ -126,7 +122,6 @@ int getsession(int pid, unsigned int ts_ttl) { int fd = open(path, O_RDONLY); if (fd < 0) { - close(fd); if (errno == ENOENT) return -1; err(1, "Could not open %s", path);