diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
index 8a11d093e103d73e37dd1d815133b1ac51213b0b..a90ca5c240e93b8c66b8ef5e4691e7e509b21a10 100644
--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -222,8 +222,8 @@ public:
 
 MatAllocator* Mat::getStdAllocator()
 {
-    static StdMatAllocator allocator;
-    return &allocator;
+    static MatAllocator * allocator = new StdMatAllocator();
+    return allocator;
 }
 
 void swap( Mat& a, Mat& b )
diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp
index 6f19b56eb5ef7b8402a54334ef420606e66417ac..9dd9f05efe0dfc15d7873e0c1353ee3ba9061f18 100644
--- a/modules/core/src/ocl.cpp
+++ b/modules/core/src/ocl.cpp
@@ -3959,8 +3959,8 @@ public:
 
 MatAllocator* getOpenCLAllocator()
 {
-    static OpenCLAllocator allocator;
-    return &allocator;
+    static MatAllocator * allocator = new OpenCLAllocator();
+    return allocator;
 }
 
 ///////////////////////////////////////////// Utility functions /////////////////////////////////////////////////