From 874e4951213d6ff8d08eeab15ee80c59fdbe318f Mon Sep 17 00:00:00 2001 From: Daniel Gnoutcheff Date: Wed, 15 Sep 2021 13:59:09 -0400 Subject: Fix memory leak, again --- app/Main.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index b667aa4..9da65af 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -85,8 +85,11 @@ rpcHtmlize args = XRI.renderResponse . XRI.Return . XRI.ValueString . htmlize $ mdwn where Just (XR.Value_AString (XR.AString mdwn)) = lookup "content" args +-- The 'mdwn' binding is mandatory. If we write this function point-free, GHC +-- floats the 'P.readMarkdown readOpts' into a CAF, and for some reason that +-- leaks memory like crazy. htmlize :: String -> String -htmlize = either (error . show) T.unpack . P.runPure . +htmlize mdwn = either (error . show) T.unpack . P.runPure . (P.writeHtml5String P.def =<<) . P.readMarkdown readOpts . T.pack . - filter (\c -> c `elem` "\t\n\r" || (c>=' ' && c/='\x7f')) + filter (\c -> c `elem` "\t\n\r" || (c>=' ' && c/='\x7f')) $ mdwn where readOpts = P.def {P.readerExtensions = P.pandocExtensions} -- cgit v1.2.1