From 83a2b566a3d7ef0850ded63fbfdae228c55af94a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 4 Feb 2014 17:23:26 +0400 Subject: [PATCH] fix memory leak for Mat::getUMat() operation --- modules/core/include/opencv2/core/mat.inl.hpp | 6 ++---- modules/core/src/matrix.cpp | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index fd7b061..e0f13a5 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -3112,8 +3112,7 @@ UMat::UMat(const UMat& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), u(m.u), offset(m.offset), size(&rows) { - if( u ) - CV_XADD(&(u->urefcount), 1); + addref(); if( m.dims <= 2 ) { step[0] = m.step[0]; step[1] = m.step[1]; @@ -3148,8 +3147,7 @@ UMat& UMat::operator = (const UMat& m) { if( this != &m ) { - if( m.u ) - CV_XADD(&(m.u->urefcount), 1); + const_cast(m).addref(); release(); flags = m.flags; if( dims <= 2 && m.dims <= 2 ) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 87e4fd5..c84724d 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -191,7 +191,6 @@ public: bool allocate(UMatData* u, int /*accessFlags*/) const { if(!u) return false; - CV_XADD(&u->urefcount, 1); return true; } -- 2.7.4