fixed db file handle leak
use tempfile for db tests