[Mono-dev] file handle leak in cpu_load
Alexander Köplinger
alex.koeplinger at outlook.com
Tue Dec 2 11:12:04 UTC 2014
Can you send a pull request on GitHub?
> Date: Tue, 2 Dec 2014 12:01:29 +0100
> From: markus.beth at zkrd.de
> To: mono-devel-list at lists.ximian.com
> Subject: [Mono-dev] file handle leak in cpu_load
>
> Hi all,
>
> last week we used the profiler of a mono 3.10.0 installation on
> Linux x86_64 and we found it leaks file handles (for /proc/loadavg).
>
> I located the problem in the function cpu_load in
> mono/utils/mono-counters.c. If a premature return is taken, the FILE
> pointer f is not fclose()-ed.
>
> I propose the following fix:
>
> ---
> mono/utils/mono-counters.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mono/utils/mono-counters.c b/mono/utils/mono-counters.c
> index 1e0840c..c669454 100644
> --- a/mono/utils/mono-counters.c
> +++ b/mono/utils/mono-counters.c
> @@ -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;
> --
>
> It applies on master and also (with an offset of -32 lines) on
> mono-3.10.0-branch.
>
> What do you think?
>
> Regards,
> Markus
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20141202/905d95e2/attachment.html>
More information about the Mono-devel-list
mailing list