Fixing memoryleaks.
Merge pull request #2234 from dumganhar/memory-leak

Fixing memoryleaks.