[counters] Fix file handle leak in cpu_load ()
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 2 Dec 2014 04:41:00 +0000 (05:41 +0100)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 2 Dec 2014 04:41:00 +0000 (05:41 +0100)
If a premature return is taken, the FILE pointer f is not fclose()-ed.

Report and fix provided by Markus Beth on the mailing list: http://lists.ximian.com/pipermail/mono-devel-list/2014-December/042459.html

mono/utils/mono-counters.c

index 1e0840c6b04a7b539d5854aadbd3874edf8afc2d..c669454054247c70274ea67e2407452c320ddfc7 100644 (file)
@@ -360,6 +360,7 @@ cpu_load (int kind)
        FILE *f = fopen ("/proc/loadavg", "r");
        if (f) {
                len = fread (buffer, 1, sizeof (buffer) - 1, f);
+               fclose (f);
                if (len > 0) {
                        buffer [len < 511 ? len : 511] = 0;
                        b = buffer;
@@ -374,7 +375,6 @@ cpu_load (int kind)
                                }
                        }
                }
-               fclose (f);
        }
 #endif
        return 0;