Fix memory handling bug.