Close cursors

Close SQL cursors to avoid leaking them