bickfordb/haskell-taglib — pull request #2 by Whoops (2013-04-17 02:24:25+00:00)
Title: add close method to explicitly free TagFiles

I've added a close method for tagfiles. Theres actually a couple reasons for this. One is simply to avoid leaking file handles in the event that the garbage collector doesn't free them up fast enough. I actually haven't been able to write a test case where this is a problem, but it's still good practice.

The other issue that I actually DID run afoul of, is it's currently easy to write code that, when compiled with `ghc -O` actually frees the TagFile before your done with it.
Consider the following snippet which inserts code into a acid-state database:

```haskell
insertFile database file = do
tagFile <- TL.open file
mTag <- TL.tag $ fromJust tagFile
let tag = fromJust mTag
artist <- TL.artist tag
album <- TL.album tag
title <- TL.title tag
genre <- TL.genre tag
comment <- TL.comment tag
track <- TL.track tag
year <- TL.year tag
update database (AddTrack file artist album title genre comment track year)
return ()
```

When compiled with optimizations GHC actually realizes that tagFile is never used, and allows it to be GCed, the resulting error is:

```
pure virtual method called
terminate called without an active exception
```

adding an explicit
```haskell
close $ fromJust tagFile
```
to that example resolves it.