Fix resource leak issue of cursor

Unclose cursor exists.