diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
index e1e9caa837..c1d2c34852 100644
--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -205,9 +205,12 @@ public:
 
     void deallocate(UMatData* u) const
     {
+        if(!u)
+            return;
+
         CV_Assert(u->urefcount >= 0);
         CV_Assert(u->refcount >= 0);
-        if(u && u->refcount == 0)
+        if(u->refcount == 0)
         {
             if( !(u->flags & UMatData::USER_ALLOCATED) )
             {