Fixed memory leaks
Merge remote-tracking branch 'pasis/memleak'