From c28cbcf859d303483ed6def8a113ed3b60375eb7 Mon Sep 17 00:00:00 2001 From: nand Date: Sun, 9 Feb 2014 01:11:13 +0100 Subject: Fix runaway memory leak when expanding invalid tags, and remove error Don't recursively parse on the case of an error. Also, in the case of an error, instead of replacing by an error message, replace by the tag itself to prevent mangling strings that legitimately include < and > characters, for example song titles when using the MPD plugin. I'm not sure how to handle this better. Honestly, I would like to remove the recursive parsing altogether but this works for now. Consider filing an issue for a proper resolution of this. I don't want rogue tags expanding themselves in my song titles. --- src/Plugins/Monitors/Common.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index a8b6542..9ebe828 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -337,10 +337,10 @@ combine :: Map.Map String String -> [(String, String, String)] -> Monitor String combine _ [] = return [] combine m ((s,ts,ss):xs) = do next <- combine m xs - let str = Map.findWithDefault err ts m - err = "<" ++ ts ++ " not found!>" - nstr <- parseTemplate' str m - return $ s ++ (if null nstr then str else nstr) ++ ss ++ next + str <- case Map.lookup ts m of + Nothing -> return $ "<" ++ ts ++ ">" + Just r -> let f "" = r; f n = n; in fmap f $ parseTemplate' r m + return $ s ++ str ++ ss ++ next -- $strings -- cgit v1.2.3