]> granicus.if.org Git - icu/commitdiff
ICU-20776 Checks for nullness in UMutex::lock()
authorFilip Filmar <filmil@gmail.com>
Thu, 15 Aug 2019 01:32:43 +0000 (18:32 -0700)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Wed, 21 Aug 2019 18:21:24 +0000 (11:21 -0700)
Adds `U_ASSERT` check before using `m->lock()` to make allocation issues
more apparent at least in debug builds.

There is probably quite a few places like this, but let's try fixing
broken windows.

icu4c/source/common/umutex.cpp
icu4c/source/common/umutex.h

index 8be43bf960c664c2975c2301d93f045822cd5455..fe50d866d4f5456f12fe6e384941c628bfa289be 100644 (file)
@@ -98,6 +98,7 @@ std::mutex *UMutex::getMutex() {
             gListHead = this;
         }
     }
+    U_ASSERT(retPtr != nullptr);
     return retPtr;
 }
 
index 13e38b49aae92e3f328567257ec7cf0185d47e78..d154ff8433916418588c17e8cf5556768a8a518b 100755 (executable)
@@ -240,7 +240,8 @@ private:
     static UMutex *gListHead;
 
     /** Out-of-line function to lazily initialize a UMutex on first use.
-     * Initial fast check is inline, in lock().
+     * Initial fast check is inline, in lock().  The returned value may never
+     * be nullptr.
      */
     std::mutex *getMutex();
 };