Permalink
Browse files

Free a Result as soon as we're done with it.

  • Loading branch information...
1 parent 2453c17 commit 3c5ee9b5c371c4255bb05bd6100e78e12e6c0f90 @bos bos committed May 4, 2011
Showing with 2 additions and 3 deletions.
  1. +2 −3 Database/MySQL/Simple.hs
View
@@ -83,7 +83,7 @@ module Database.MySQL.Simple
import Blaze.ByteString.Builder (Builder, fromByteString, toByteString)
import Blaze.ByteString.Builder.Char8 (fromChar)
import Control.Applicative ((<$>), pure)
-import Control.Exception (Exception, onException, throw, throwIO)
+import Control.Exception (Exception, bracket, onException, throw, throwIO)
import Control.Monad.Fix (fix)
import Data.ByteString (ByteString)
import Data.Int (Int64)
@@ -326,8 +326,7 @@ finishFold conn q z0 f = withResult (Base.useResult conn) q $ \r fs ->
_ -> (f z $! convertResults fs row) >>= loop
withResult :: (IO Result) -> Query -> (Result -> [Field] -> IO a) -> IO a
-withResult fetchResult q act = do
- r <- fetchResult
+withResult fetchResult q act = bracket fetchResult Base.freeResult $ \r -> do
ncols <- Base.fieldCount (Right r)
if ncols == 0
then throwIO $ QueryError "query resulted in zero-column result" q

0 comments on commit 3c5ee9b

Please sign in to comment.