[project @ 2003-07-25 10:03:51 by simonmar]
authorsimonmar <unknown>
Fri, 25 Jul 2003 10:03:51 +0000 (10:03 +0000)
committersimonmar <unknown>
Fri, 25 Jul 2003 10:03:51 +0000 (10:03 +0000)
regcomp: don't attach the regfree finalizer if c_regcomp failed.

Text/Regex/Posix.hsc

index 9cc06f7..1937884 100644 (file)
@@ -60,9 +60,9 @@ regcomp pattern flags = do
   r <- withCString pattern $ \cstr ->
         withForeignPtr regex_fptr $ \p ->
            c_regcomp p cstr (fromIntegral flags)
-  addForeignPtrFinalizer regex_fptr ptr_regfree
   if (r == 0)
-     then return (Regex regex_fptr)
+     then do addForeignPtrFinalizer regex_fptr ptr_regfree
+            return (Regex regex_fptr)
      else error "Text.Regex.Posix.regcomp: error in pattern" -- ToDo
 
 -- -----------------------------------------------------------------------------