Merge pull request #9776 from IgWod:matrix-memory-leak-fix

Fix memory leak in the matrix copying constructor
pull/9840/head
Alexander Alekhin 7 years ago committed by GitHub
commit ae52d94ceb
  1. 14
      modules/core/src/matrix.cpp

@ -279,9 +279,12 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : size(&r
}
*this = m;
try
{
if( _rowRange != Range::all() && _rowRange != Range(0,rows) )
{
CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows );
CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end
&& _rowRange.end <= m.rows );
rows = _rowRange.size();
data += step*_rowRange.start;
flags |= SUBMATRIX_FLAG;
@ -289,12 +292,19 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : size(&r
if( _colRange != Range::all() && _colRange != Range(0,cols) )
{
CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols );
CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end
&& _colRange.end <= m.cols );
cols = _colRange.size();
data += _colRange.start*elemSize();
flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1;
flags |= SUBMATRIX_FLAG;
}
}
catch(...)
{
release();
throw;
}
if( rows == 1 )
flags |= CONTINUOUS_FLAG;

Loading…
Cancel
Save