Skip to content

Commit 853d485

Browse files
ethercrowBodigrim
authored andcommitted
Fix hGetContents_crash
1 parent d2e7599 commit 853d485

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests/Tests/Regressions.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import qualified Data.Text.Lazy.Encoding as LE
2828
import qualified Data.Text.Unsafe as T
2929
import qualified Test.Tasty as F
3030
import qualified Test.Tasty.HUnit as F
31+
import System.Directory (removeFile)
3132

3233
import Tests.Utils (withTempFile)
3334

@@ -42,12 +43,15 @@ lazy_encode_crash = withTempFile $ \ _ h ->
4243
-- encoded file can result in a crash in the RTS (i.e. not merely an
4344
-- exception).
4445
hGetContents_crash :: IO ()
45-
hGetContents_crash = withTempFile $ \ path h -> do
46+
hGetContents_crash = do
47+
(path, h) <- openTempFile "." "crashy.txt"
4648
B.hPut h (B.pack [0x78, 0xc4 ,0x0a]) >> hClose h
4749
h' <- openFile path ReadMode
4850
hSetEncoding h' utf8
4951
handle (\(_::SomeException) -> return ()) $
5052
T.hGetContents h' >> assertFailure "T.hGetContents should crash"
53+
hClose h'
54+
removeFile path
5155

5256
-- Reported by Ian Lynagh: attempting to allocate a sufficiently large
5357
-- string (via either Array.new or Text.replicate) could result in an

0 commit comments

Comments
 (0)