Bugfix: file output may cause segfault on mac os.