Fixes of some memory leaks
Added pointer initialization
Merge pull request #1839 from pmiecielica:memory_leaks