mirror of https://github.com/xzeldon/htop.git
Fix file descriptor leak in LinuxProcessList_readCmdlineFile after xread failure
Found by Coverity
This commit is contained in:
parent
21e3063e2e
commit
4af8c63f63
|
@ -1023,7 +1023,6 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||
xSnprintf(filename, MAX_NAME, "%s/%s/comm", dirname, name);
|
||||
if ((fd = open(filename, O_RDONLY)) != -1 &&
|
||||
(amtRead = xread(fd, command, sizeof(command) - 1)) > 0) {
|
||||
close(fd);
|
||||
command[amtRead - 1] = 0;
|
||||
lp->mergedCommand.maxLen += amtRead - 1; /* accomodate comm */
|
||||
if (!lp->procComm || strcmp(command, lp->procComm)) {
|
||||
|
@ -1037,6 +1036,9 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||
lp->mergedCommand.commChanged = true;
|
||||
}
|
||||
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
|
||||
/* execve could change /proc/[pid]/exe, so procExe should be udpated */
|
||||
xSnprintf(command, sizeof(command), "%s/%s/exe", dirname, name);
|
||||
if ((amtRead = readlink(command, filename, sizeof(filename) - 1)) > 0) {
|
||||
|
|
Loading…
Reference in New Issue