Fixing memory leak issue exposed by SHARK-116
Merge pull request #737 from c0s/SHARK-116

Fixing memory leak issue exposed by SHARK-116