From d7aeb5f545bf41d4d735afd9dd070501f540f61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 30 Nov 2017 10:30:29 +0300 Subject: [PATCH] withDev: Close the FD on exception --- Crypto/Random/Entropy/Unix.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Crypto/Random/Entropy/Unix.hs b/Crypto/Random/Entropy/Unix.hs index 9a7400c..a8aae43 100644 --- a/Crypto/Random/Entropy/Unix.hs +++ b/Crypto/Random/Entropy/Unix.hs @@ -58,7 +58,7 @@ withDev :: String -> (H -> IO a) -> IO a withDev filepath f = openDev filepath >>= \h -> case h of Nothing -> error ("device " ++ filepath ++ " cannot be grabbed") - Just fd -> f fd >>= \r -> (closeDev fd >> return r) + Just fd -> f fd `E.finally` closeDev fd closeDev :: H -> IO () closeDev h = hClose h