[flang-commits] [PATCH] D101928: [flang] Fix race condition in runtime

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu May 6 11:14:30 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f41994c1374: [flang] Fix race condition in runtime (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101928/new/

https://reviews.llvm.org/D101928

Files:
  flang/runtime/io-error.cpp
  flang/runtime/terminator.cpp
  flang/runtime/unit.cpp


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -205,16 +205,20 @@
   }
   Terminator terminator{__FILE__, __LINE__};
   IoErrorHandler handler{terminator};
-  unitMap = New<UnitMap>{terminator}().release();
-  ExternalFileUnit &out{ExternalFileUnit::CreateNew(6, terminator)};
+  UnitMap *newUnitMap{New<UnitMap>{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;
 }
 
Index: flang/runtime/terminator.cpp
===================================================================
--- flang/runtime/terminator.cpp
+++ 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 &){
Index: flang/runtime/io-error.cpp
===================================================================
--- flang/runtime/io-error.cpp
+++ 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101928.343461.patch
Type: text/x-patch
Size: 2038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210506/66ffbc7e/attachment-0001.bin>


More information about the flang-commits mailing list