From cf4e9e5ce2d0a709eb7fd8b84fd70bf44a25bb8c Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Wed, 10 May 2017 16:04:02 -0700 Subject: [PATCH] Update matrix.cpp Fix race condition in getDefaultAllocator and setDefaultAllocator interaction / not threadsafe currently --- modules/core/src/matrix.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 50a0856843..b02613e837 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -222,7 +222,7 @@ public: }; namespace { - MatAllocator* g_matAllocator = NULL; + MatAllocator* volatile g_matAllocator = NULL; } @@ -230,7 +230,11 @@ MatAllocator* Mat::getDefaultAllocator() { if (g_matAllocator == NULL) { - g_matAllocator = getStdAllocator(); + cv::AutoLock lock(cv::getInitializationMutex()); + if (g_matAllocator == NULL) + { + g_matAllocator = getStdAllocator(); + } } return g_matAllocator; }