Merge pull request #205 from osa1/close_dev_handle

withDev: Close the FD on exception
This commit is contained in:
Vincent Hanquez 2017-12-17 18:15:31 +00:00 committed by GitHub
commit c02c43bfc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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