BUG: Memory leaks detectd by valgrind

The new unit test uncovered memory leaks mainly during error
processing.

Change-Id: Icd2b9bd5fa4a69e89114b3a805a521f9bc608cfc
Merge topic 'FunctionParserMemoryLeak' into master

8597cc58 BUG: Memory leaks detectd by valgrind