From e16a3598a9539e07465fd03f591e3327a617b906 Mon Sep 17 00:00:00 2001 From: tsujan Date: Sat, 4 Nov 2023 10:53:02 +0330 Subject: [PATCH] Fixed instances of non-closed file descriptors (#454) One of the instances wasn't really used by the code, but the other was and its fix resulted in a reduction in Qps's opened file handles. --- src/proc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/proc.cpp b/src/proc.cpp index f147bc4..9ccb396 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -154,6 +154,7 @@ char *read_proc_file(const char *fname, int pid = -1, int tgid = -1, if (fd < 0) return nullptr; r = read(fd, buffer_proc, sizeof(buffer_proc) - 1); // return 0 , -1 , + close(fd); if (r < 0) return nullptr; @@ -195,6 +196,7 @@ char *read_proc_file2(char *r_path, const char *fname, int *size = nullptr) return nullptr; r = read(fd, buffer_proc, sizeof(buffer_proc) - 1); // return 0 , -1 , read_count + close(fd); if (r < 0) return nullptr; @@ -205,7 +207,6 @@ char *read_proc_file2(char *r_path, const char *fname, int *size = nullptr) *size = r; buffer_proc[r] = 0; // safer - close(fd); return buffer_proc; // note: not work fgets(sbuf, sizeof(64), fp) why???