From 3849fed8381f1751f1573024726d976660b64afc Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Thu, 10 Sep 2015 22:07:19 +0200 Subject: [PATCH] Fix not closing files from /proc/ on read errors The cmdline files opened from /proc/ were not closed if reading the data from them failed (e.g. because the file was empty). This leaked the file descriptor which could lead to failures trying to open more files later. --- src/lib/3rdparty/processinfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/3rdparty/processinfo.cpp b/src/lib/3rdparty/processinfo.cpp index 1bba34461..cb73df3a5 100644 --- a/src/lib/3rdparty/processinfo.cpp +++ b/src/lib/3rdparty/processinfo.cpp @@ -85,12 +85,12 @@ pid_t ProcessInfo::GetPIDbyName(const char* cchrptr_ProcessName) const if (fd_CmdLineFile) { int r = fscanf(fd_CmdLineFile, "%20s", chrarry_NameOfProcess) ; // read from /proc//cmdline + fclose(fd_CmdLineFile); // close the file prior to exiting the routine + if (r < 1) { continue; } - fclose(fd_CmdLineFile); // close the file prior to exiting the routine - if (strrchr(chrarry_NameOfProcess, '/')) { chrptr_StringToCompare = strrchr(chrarry_NameOfProcess, '/') + 1 ; }