[erlang-patches] cover: fix file descriptor leak

shunichi shinohara <>
Fri Apr 29 08:07:41 CEST 2011

The patch below fixes file descriptor leak of cover module.

  git fetch https://github.com/shino/otp.git shino/fix-cover-fd-leak


Data import of cover module is called with a file path and
open a fd internally. The fd should be closed in cover module,
but it does not.
As an additional information, in data export it closes a fd properly.

This patch does not include test code because
  - I can't find the way to execute test suites, and
  - I don't know how to find fd list in beam process.

Steps to reproduce:

I tested the patch on Mac OS X 10.6.7, 64bit.

1. Run the escript below, and find the process id (OS pid).
#!/usr/bin/env escript

main([]) ->
    file:write_file("sample.erl", <<"-module(sample).\n">>),
    {ok, sample} = cover:compile("sample.erl"),
    ok = cover:export("sample.coverdata", sample),
    ok = cover:import("sample.coverdata"),
    io:format("~s~n", [os:cmd("lsof -p " ++ os:getpid())]).

2. Confirm cover's data file is NOT listed in output.

   Before apply this patch, script outputs the line like:
   beam.smp 17008 shino 11r REG 14,5 89 567192 /path/to/sample.coverdata

   After this patch is applied, lsof does not report "sample.coverdata".

Shunichi Shinohara ()

More information about the erlang-patches mailing list