Rick's local

Fix resource leak issue for cursors.