Resource leaks fixes

Resource leaks fixes