From 9981a9d1e40ba45469cb974f87b583c3ac47a831 Mon Sep 17 00:00:00 2001 From: Ziyao Date: Mon, 18 Mar 2024 21:46:51 +0800 Subject: [PATCH] Fix memory leak in Haskell binding and simpily example (#86) --- README.md | 2 +- haskell/Ruapu.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c72eeab..d237066 100644 --- a/README.md +++ b/README.md @@ -327,7 +327,7 @@ import Ruapu main = do Ruapu.init Ruapu.supports "mmx" >>= putStrLn . show - Ruapu.rua >>= foldl (\m x -> m >> putStrLn x) (return ()) + Ruapu.rua >>= sequence_ . map putStrLn ``` diff --git a/haskell/Ruapu.hs b/haskell/Ruapu.hs index 075c4fc..07086cb 100644 --- a/haskell/Ruapu.hs +++ b/haskell/Ruapu.hs @@ -3,7 +3,7 @@ module Ruapu where import Foreign -import Foreign.C.String (CString, newCAString, peekCAString) +import Foreign.C.String (CString, withCAString, peekCAString) foreign import ccall "ruapu.c ruapu_init" init :: IO () @@ -15,7 +15,7 @@ foreign import ccall "ruapu.c ruapu_rua" cRua :: IO (Ptr CString) supports :: String -> IO Bool -supports xs = (newCAString xs) >>= cSupports +supports = flip withCAString cSupports rua :: IO [String] rua = cRua >>= peekArray0 nullPtr >>= mapM peekCAString