Fix memory leak and possible performance hit
Merge pull request #345 from kraz/master

Fix memory leak and possible performance hit