withDev: Close the FD on exception
This commit is contained in:
parent
5e354f9bfc
commit
d7aeb5f545
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user