summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-15 13:59:09 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-15 14:02:21 -0400
commit874e4951213d6ff8d08eeab15ee80c59fdbe318f (patch)
tree507e0b83060ee5642dd577c15413915f3b05f198
parente0029580b656a73f5804929880009fcdc8c03721 (diff)
Fix memory leak, again
-rw-r--r--app/Main.hs7
1 files 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}