diff --git a/indra/llmessage/llmessagetemplateparser.cpp b/indra/llmessage/llmessagetemplateparser.cpp
index 283547ea009dbde38d208e400b96930e6822fb38..2ddbf3e0df077f1b148f817698919e16a92dd34f 100644
--- a/indra/llmessage/llmessagetemplateparser.cpp
+++ b/indra/llmessage/llmessagetemplateparser.cpp
@@ -403,6 +403,10 @@ LLTemplateParser::LLTemplateParser(LLTemplateTokenizer & tokens):
 		{
 			mMessages.push_back(templatep);
 		}
+		else
+		{
+			delete templatep;
+		}
 	}
 
 	if(!tokens.wantEOF())