Crash in FMallocBinned when using ifstream or ofsteam

The code in my plugin simply does this in AGameModeBase::StartPlay.

    std::ifstream f;
    std::cout << f.is_open();

This works in Windows but on Linux this results in crash (we are using Clang 3.9 on Ubuntu 16.04. It appears that when ifstream destructor runs, it calls FMallocBinned which crahses because it tries to access invalid address. Below is crash report:

Crash report

[2017.07.13-03.31.17:045][574]LogLinux: === Critical error: ===
Unhandled Exception: SIGSEGV: invalid attempt to read memory at address 0x0000000000000002

[2017.07.13-03.31.17:045][574]LogLinux: Fatal error!

[Callstack]  00  0x00007f230fb6af7f  FLinuxPlatformStackWalk::CaptureStackBackTrace(unsigned long long*, unsigned int, void*)
[Callstack]  01  0x00007f230fa53f65  FGenericPlatformStackWalk::StackWalkAndDump(char*, unsigned long, int, void*)
[Callstack]  02  0x00007f230fb2c361  FLinuxCrashContext::CaptureStackTrace()
[Callstack]  03  0x00007f2305d691c0  CommonLinuxCrashHandler(FGenericCrashContext const&)
[Callstack]  04  0x00007f230fb304da  PlatformCrashHandler(int, siginfo_t*, void*)
[Callstack]  05  0x00007f2315829390  /lib/x86_64-linux-gnu/ [0x7f2315829390]
[Callstack]  06  0x00007f230fad0d48  FMallocBinned::Private::FreeInternal(FMallocBinned&, void*)
[Callstack]  07  0x00007f229ac02c6a  std::__1::basic_filebuf<char, std::__1::char_traits<char> >::~basic_filebuf()
[Callstack]  08  0x00007f229abfa911  msr::airlib::Settings::saveJSonFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)

Hey sytelus-

What engine version are you running on your Linux machine? I tried adding the code you provided to a GameModeBase in 4.18 and did not get a crash when StartPlay was called. 4.16.3 introduced a fix with an external STL code, so if you are using an earlier version then this may be the issue. Let me know if you’re still seeing this crash in the latest version.