memory leak fixes
Merge pull request #2340 from ptraczyk/MT_memleak_fixes

memory leak fixes