close and free the open database on destroy

Change-Id: Ib227bd73a9ffcfb975482312ea5c559c68d40efe