ENH: Fixed memory leaks