Fix bug memory leaks