bug-65: close db and cursor if missing
Merge pull request #17 from john-hu/bug-65-db-leak

bug-65: close db and cursor if missing, r=thomas