Close pat cursor in opened function