Fix memory leak in DB