haskell-suite / haskell-src-exts

Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer
Other
193 stars 94 forks source link

hClose not being called #459

Open msrdic opened 3 years ago

msrdic commented 3 years ago

Hi – I've discovered this one by mistakenly calling my tool in the wrong folder.

hClose is not being called after Language.Haskell.Exts.parseFile is done. It can result in too many files open error.

I've identified two places where file content is being read and hClose is not being called, the first one being the one described above, and the second one in a test runner (test/Runner.hs).

Steps to reproduce: the way I discovered this is by recursively calling parseFile on a complete source tree for the folder where I keep my source code. Possible fix: I've verified in my own fork that a combination of a strict hGetContents and hClose works well. It can either be done by System.IO.Strict.hGetContents or by just copying this short implementation to keep the list of dependencies shorter.

I am happy to submit a pull request, assuming this is a valid issue and I am not completely off target or missing something.

DanBurton commented 3 years ago

@msrdic This sounds reasonable to me. I would be happy to accept such a pull request.

msrdic commented 3 years ago

@DanBurton it took a while, but it seems that CI passed successfully. This is a small change, but please advise if there's anything else that should be addressed (style, structure etc). Thanks.