fix use after free if the closure returns true