]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
clean up after several functions
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 16 Feb 2015 22:33:53 +0000 (16:33 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 16 Feb 2015 22:33:53 +0000 (16:33 -0600)
which weren't freeing line of closing an open file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
lxcfs.c

diff --git a/lxcfs.c b/lxcfs.c
index d6fb101b8a33bec4642c20db2baf7927a21f3f2a..3cdfb6dd016496525bb238e71bb5da44ff413a28 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -1505,6 +1505,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                total_len += l;
        }
 
+       fclose(f);
+       free(line);
        return total_len;
 }
 
@@ -1631,6 +1633,8 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
                }
        }
 
+       fclose(f);
+       free(line);
        return total_len;
 }
 
@@ -1685,6 +1689,8 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
                total_len += l;
        }
 
+       fclose(f);
+       free(line);
        return total_len;
 }
 
@@ -1808,9 +1814,12 @@ static long int getprocidle(void)
 {
        FILE *f = fopen("/proc/uptime", "r");
        long int age, idle;
+       int ret;
        if (!f)
                return 0;
-       if (fscanf(f, "%ld %ld", &age, &idle) != 2)
+       ret = fscanf(f, "%ld %ld", &age, &idle);
+       fclose(f);
+       if (ret != 2)
                return 0;
        return idle;
 }
@@ -1844,6 +1853,7 @@ static off_t get_procfile_size(const char *which)
        while ((sz = getline(&line, &len, f)) != -1)
                answer += sz;
        fclose (f);
+       free(line);
 
        return answer;
 }