[Xfce4-commits] [apps/xfce4-taskmanager] 03/20: Fix possible file descriptor leak on linux (bug 14401)

noreply at xfce.org noreply at xfce.org
Wed May 30 22:00:17 CEST 2018


This is an automated email from the git hooks/post-receive script.

l   a   n   d   r   y       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-taskmanager.

commit 40a3e65803a87770138d49acf79da33398497f6a
Author: rim <rozhuk.im at gmail.com>
Date:   Tue May 29 02:47:00 2018 +0300

    Fix possible file descriptor leak on linux (bug 14401)
---
 src/task-manager-linux.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index 71d5ca0..a62c5a0 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -71,8 +71,13 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
 	static gulong jiffies_user_old = 0, jiffies_system_old = 0, jiffies_total_old = 0;
 	gulong user = 0, user_nice = 0, system = 0, idle = 0;
 
-	if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL)
+	if ((file = fopen (filename, "r")) == NULL)
 		return FALSE;
+	if (fgets (buffer, sizeof(buffer), file) == NULL)
+	{
+		fclose (file);
+		return FALSE;
+	}
 
 	sscanf (buffer, "cpu\t%lu %lu %lu %lu", &user, &user_nice, &system, &idle);
 
@@ -195,8 +200,13 @@ get_task_details (GPid pid, Task *task)
 	gchar buffer[1024];
 
 	snprintf (filename, sizeof(filename), "/proc/%d/stat", pid);
-	if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL)
+	if ((file = fopen (filename, "r")) == NULL)
 		return FALSE;
+	if (fgets (buffer, sizeof(buffer), file) == NULL)
+	{
+		fclose (file);
+		return FALSE;
+	}
 	fclose (file);
 
 	bzero(task, sizeof(Task));

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list