Fix `Handle` leak

If limit to open files is low, ResourceExhausted exception occurs at hDuplicate in Test.Main.redirectingHandle. You can reproduce this exception by changing the limit using ulimit -n 256 (or else) on Unix.

I added hClose to fix this exception.

$ ulimit -n  # limit to open files
256

$ cabal new-test
Build profile: -w ghc-8.6.4 -O1
In order, the following will be built (use -v for more details):
 - main-tester-0.2.0.0 (test:main-tester-test) (first run)
Preprocessing test suite 'main-tester-test' for main-tester-0.2.0.0..
Building test suite 'main-tester-test' for main-tester-0.2.0.0..
Running 1 test suites...
Test suite main-tester-test: RUNNING...

Test.Main
  passes stdin and arguments to the program, and captures stdin data, stderr data, and exit code FAILED [1]
  captures stdin data, stderr data, exit code, and thrown exception when the program throws an exception FAILED [2]
  overwrites or deletes the specified environment variables temporarily

Failures:

  test/Spec.hs:39:5: 
  1) Test.Main passes stdin and arguments to the program, and captures stdin data, stderr data, and exit code
       uncaught exception: IOException of type ResourceExhausted
       /var/folders/jp/gcwg7_vs2gjbzgy26gbw8v_00000gn/T/: openBinaryTempFile: resource exhausted (Too many open files)
       (after 76 tests and 1 shrink)
         ([],PrintableAsciiString {getPrintableAsciiString = "d#%AUj-JvEl4<sNxSiR-@'o+x>A,L|x~+YriN_~+n"},AExitCode ExitSuccess)

  To rerun use: --match "/Test.Main/passes stdin and arguments to the program, and captures stdin data, stderr data, and exit code/"

  test/Spec.hs:53:5: 
  2) Test.Main captures stdin data, stderr data, exit code, and thrown exception when the program throws an exception
       uncaught exception: IOException of type ResourceExhausted
       /var/folders/jp/gcwg7_vs2gjbzgy26gbw8v_00000gn/T/: openBinaryTempFile: resource exhausted (Too many open files)
       (after 1 test)
         (PrintableAsciiString {getPrintableAsciiString = ""},PrintableAsciiString {getPrintableAsciiString = ""},"")

  To rerun use: --match "/Test.Main/captures stdin data, stderr data, exit code, and thrown exception when the program throws an exception/"

Randomized with seed 1629384564

Finished in 0.1983 seconds
3 examples, 2 failures
Test suite main-tester-test: FAIL
Test suite logged to:
/Users/cohey/src/gitlab.com/igrep/main-tester/dist-newstyle/build/x86_64-osx/ghc-8.6.4/main-tester-0.2.0.0/t/main-tester-test/test/main-tester-0.2.0.0-main-tester-test.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:main-tester-test from main-tester-0.2.0.0.

Merge request reports

Loading