From: Sebastien Godard Date: Thu, 5 May 2011 09:07:43 +0000 (+0200) Subject: Close file descriptor in read_uptime() function (file rd_stats.c). X-Git-Tag: v10.0.1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd057acc9adbfa763c371df81cfba733f55403ed;p=sysstat Close file descriptor in read_uptime() function (file rd_stats.c). File descriptor was not closed when /proc/uptime file happened to be empty. Mail from Ivana Varekova (varekova@redhat.com) 02/05/2011: Subject: feature request: Resizing device column in iostat to size of larges lvm device name Hello, I'm sending three patches against sysstat-10.0.0: [...] * sysstat_2.patch fix rear_uptime bug - this function does not close the file descriptor which is open in it in the special situation [...] If you need a clarification to arbitrary of them please sent me an e-mail. Ivana --- diff --git a/CHANGES b/CHANGES index fb7b090..85326a3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Changes: xxxx/xx/xx: Version 10.0.1 - Sebastien Godard (sysstat orange.fr) + * [Ivana Varekova]: Close file descriptor in read_uptime() + function (file rd_stats.c). * NLS updated. Esperanto translation added. 2011/03/15: Version 10.0.0 - Sebastien Godard (sysstat orange.fr) @@ -379,7 +381,7 @@ xxxx/xx/xx: Version 10.0.1 - Sebastien Godard (sysstat orange.fr) done in one place (common function used by iostat, sar, sadf). * All sysstat commands are made consistent with how parameters are interpreted: "COMMAND " now generates a report - continusouly, "COMMAND 0" causes an error, + continuously, "COMMAND 0" causes an error, "COMMAND 0" displays a report since system startup [DEBIAN bug#475707]. * Changed XML output for processes and context switches displayed diff --git a/rd_stats.c b/rd_stats.c index cb3b46f..41a511c 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -1759,8 +1759,10 @@ void read_uptime(unsigned long long *uptime) if ((fp = fopen(UPTIME, "r")) == NULL) return; - if (fgets(line, 128, fp) == NULL) + if (fgets(line, 128, fp) == NULL) { + fclose(fp); return; + } sscanf(line, "%lu.%lu", &up_sec, &up_cent); *uptime = (unsigned long long) up_sec * HZ +