database cursor leak fix