diff --git a/flang/runtime/io-error.cpp b/flang/runtime/io-error.cpp --- a/flang/runtime/io-error.cpp +++ b/flang/runtime/io-error.cpp @@ -36,12 +36,14 @@ va_start(ap, msg); std::vsnprintf(buffer, sizeof buffer, msg, ap); ioMsg_ = SaveDefaultCharacter(buffer, std::strlen(buffer) + 1, *this); + va_end(ap); } } } else if (msg) { va_list ap; va_start(ap, msg); CrashArgs(msg, ap); + va_end(ap); } else if (const char *errstr{IostatErrorString(iostatOrErrno)}) { Crash(errstr); } else { diff --git a/flang/runtime/terminator.cpp b/flang/runtime/terminator.cpp --- a/flang/runtime/terminator.cpp +++ b/flang/runtime/terminator.cpp @@ -16,6 +16,7 @@ va_list ap; va_start(ap, message); CrashArgs(message, ap); + va_end(ap); } static void (*crashHandler)(const char *, int, const char *, va_list &){ diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -205,16 +205,20 @@ } Terminator terminator{__FILE__, __LINE__}; IoErrorHandler handler{terminator}; - unitMap = New{terminator}().release(); - ExternalFileUnit &out{ExternalFileUnit::CreateNew(6, terminator)}; + UnitMap *newUnitMap{New{terminator}().release()}; + bool wasExtant{false}; + ExternalFileUnit &out{newUnitMap->LookUpOrCreate(6, terminator, wasExtant)}; + RUNTIME_CHECK(terminator, !wasExtant); out.Predefine(1); out.SetDirection(Direction::Output, handler); defaultOutput = &out; - ExternalFileUnit &in{ExternalFileUnit::CreateNew(5, terminator)}; + ExternalFileUnit &in{newUnitMap->LookUpOrCreate(5, terminator, wasExtant)}; + RUNTIME_CHECK(terminator, !wasExtant); in.Predefine(0); in.SetDirection(Direction::Input, handler); defaultInput = ∈ // TODO: Set UTF-8 mode from the environment + unitMap = newUnitMap; return *unitMap; }