Properly close the cursor in to avoid leaking resources

Running an app in strict mode shows this as a potential memory leak