Memory management fix