From c74a06e761c3a4616a92fd4d3ad0ac9edb97e06c Mon Sep 17 00:00:00 2001 From: defanor Date: Sun, 29 Apr 2018 13:09:40 +0300 Subject: Introduce InitializerMaybe, initializeMaybe, withNewMaybe So that it's easier to use it safely: apparently the recently found segfault was caused by improper order of freeing the resources, while withNew/withNewMaybe help to ensure the correct order. --- Redland/Util.hs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'Redland/Util.hs') diff --git a/Redland/Util.hs b/Redland/Util.hs index c7862be..0c294ab 100644 --- a/Redland/Util.hs +++ b/Redland/Util.hs @@ -181,17 +181,9 @@ statementToTriple statement = do pure $ Triple s p o where componentToTriple :: (ForeignPtr RedlandStatement -> - IO (Maybe (ForeignPtr RedlandNode))) + InitializerMaybe RedlandNode) -> IO (Maybe Node) - componentToTriple f = do - c <- f statement - case c of - Just c' -> do - n <- redlandNodeToNode c' - -- segfaulting without finalization here, not sure why. - finalizeForeignPtr c' - pure $ Just n - Nothing -> pure Nothing + componentToTriple f = withNewMaybe (f statement) redlandNodeToNode -- | A conversion function. tripleToStatement :: ForeignPtr RedlandWorld -- cgit v1.2.3