fixed some mem leakage
Merge pull request #284 from AntonioCollarino/mem_leakage

fixed some mem leakage