fix leak in function