diff --git a/Graphics/Text/Font/Choose/FontSet.hs b/Graphics/Text/Font/Choose/FontSet.hs
--- a/Graphics/Text/Font/Choose/FontSet.hs
+++ b/Graphics/Text/Font/Choose/FontSet.hs
@@ -10,6 +10,7 @@
 import Foreign.Marshal.Array (peekArray)
 import Control.Monad (forM)
 import Control.Exception (bracket)
+import System.IO.Unsafe (unsafeInterleaveIO)
 
 -- For CSS bindings
 import Stylist.Parse (StyleSheet(..), parseProperties)
@@ -58,7 +59,11 @@
     n <- get_fontSet_nfont fonts'
     if n == 0 then return []
     else
-        forM [0..pred n] (\i -> thawPattern =<< get_fontSet_font fonts' i)
+        forM [0..pred n] (\i -> thawPattern' =<< get_fontSet_font fonts' i)
+  where
+    thawPattern' pat = do
+        fcPatternReference pat
+        unsafeInterleaveIO $ thawPattern pat
 foreign import ccall "get_fontSet_nfont" get_fontSet_nfont :: FontSet_ -> IO Int
 foreign import ccall "get_fontSet_font" get_fontSet_font :: FontSet_ -> Int -> IO Pattern_
 
diff --git a/Graphics/Text/Font/Choose/Pattern.hs b/Graphics/Text/Font/Choose/Pattern.hs
--- a/Graphics/Text/Font/Choose/Pattern.hs
+++ b/Graphics/Text/Font/Choose/Pattern.hs
@@ -2,6 +2,7 @@
 module Graphics.Text.Font.Choose.Pattern (Pattern(..), Binding(..), equalSubset,
     normalizePattern, filter, defaultSubstitute, nameParse, nameUnparse, format,
     Pattern_, withPattern, thawPattern, thawPattern_, patternAsPointer,
+    fcPatternReference,
 
     setValue, setValues, unset, getValues, getValues', getValue, getValue', getValue0,
     parseFontFamily, parseFontFeatures, parseFontVars, parseLength,
@@ -16,12 +17,14 @@
 import GHC.Generics (Generic)
 import Graphics.Text.Font.Choose.Result (throwFalse, throwNull, throwInt)
 
-import Foreign.Ptr (Ptr)
+import Foreign.Ptr (Ptr, FunPtr)
+import Foreign.ForeignPtr (ForeignPtr,
+        newForeignPtr, withForeignPtr, mallocForeignPtrBytes)
 import Foreign.Marshal.Alloc (alloca, allocaBytes, free)
 import Foreign.Storable (Storable(..))
 import Foreign.C.String (CString, withCString, peekCString)
 import Debug.Trace (trace) -- For reporting internal errors!
-import System.IO.Unsafe (unsafePerformIO)
+import System.IO.Unsafe (unsafePerformIO, unsafeInterleaveIO)
 
 import Control.Monad (forM, join)
 import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
@@ -160,20 +163,23 @@
 type PatternIter_ = Ptr PatternIter'
 foreign import ccall "size_PatternIter" patIter'Size :: Int
 thawPattern :: Pattern_ -> IO Pattern
-thawPattern pat' = allocaBytes patIter'Size $ \iter' -> do
-    fcPatternIterStart pat' iter'
-    ret <- go iter'
+thawPattern pat' = do
+    iter <- mallocForeignPtrBytes patIter'Size
+    pat <- gcPattern pat'
+    with2ForeignPtrs pat iter fcPatternIterStart
+    ret <- go pat iter
     return $ normalizePattern ret
   where
-    go :: PatternIter_ -> IO Pattern
-    go iter' = do
-        ok <- fcPatternIterIsValid pat' iter'
+    go :: ForeignPtr Pattern' -> ForeignPtr PatternIter' -> IO Pattern
+    go pat iter = unsafeInterleaveIO $ do
+        ok <- with2ForeignPtrs pat iter fcPatternIterIsValid
         if ok then do
-            x <- thawPattern' pat' iter'
-            ok' <- fcPatternIterNext pat' iter'
-            xs <- if ok' then go iter' else return []
+            x <- with2ForeignPtrs pat iter thawPattern'
+            ok' <- with2ForeignPtrs pat iter fcPatternIterNext
+            xs <- if ok' then go pat iter else return []
             return (x : xs)
         else return []
+    with2ForeignPtrs a b cb = withForeignPtr a $ \a' -> withForeignPtr b $ cb a'
 foreign import ccall "FcPatternIterStart" fcPatternIterStart ::
     Pattern_ -> PatternIter_ -> IO ()
 foreign import ccall "FcPatternIterIsValid" fcPatternIterIsValid ::
@@ -208,6 +214,13 @@
 withNewPattern cb = bracket (throwNull <$> fcPatternCreate) fcPatternDestroy cb
 foreign import ccall "FcPatternCreate" fcPatternCreate :: IO Pattern_
 foreign import ccall "FcPatternDestroy" fcPatternDestroy :: Pattern_ -> IO ()
+foreign import ccall "&FcPatternDestroy" fcPatternDestroy' ::
+    FunPtr (Pattern_ -> IO ())
+
+gcPattern :: Pattern_ -> IO (ForeignPtr Pattern')
+gcPattern pat' = do
+    fcPatternReference pat'
+    newForeignPtr fcPatternDestroy' pat'
 
 ------
 --- Pattern
diff --git a/fontconfig-pure.cabal b/fontconfig-pure.cabal
--- a/fontconfig-pure.cabal
+++ b/fontconfig-pure.cabal
@@ -10,7 +10,7 @@
 -- PVP summary:      +-+------- breaking API changes
 --                   | | +----- non-breaking API additions
 --                   | | | +--- code changes with no API change
-version:             0.3.0.0
+version:             0.3.0.1
 
 -- A short (one-line) description of the package.
 synopsis:            Pure-functional language bindings to FontConfig
