Fix two DB-related memory leaks