Fix file descriptor leak in filesystem db