[fix] Resource leaks and variable tainting. Test OK