Fix db cursor leak