Skip to content

Commit

Permalink
Fixed instances of non-closed file descriptors (#454)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tsujan authored Nov 4, 2023
1 parent d3b69b8 commit e16a359
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/proc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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???
Expand Down

0 comments on commit e16a359

Please sign in to comment.