Skip to content

Commit 0d7aeac

Browse files
committed
Merge pull request opencv#9230 from alalek:mat_cleanup_on_exception
2 parents 0194d5a + 7f3eea6 commit 0d7aeac

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

modules/core/src/matrix.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void MatAllocator::unmap(UMatData* u) const
6060
if(u->urefcount == 0 && u->refcount == 0)
6161
{
6262
deallocate(u);
63-
u = NULL;
6463
}
6564
}
6665

@@ -461,8 +460,11 @@ void Mat::copySize(const Mat& m)
461460
void Mat::deallocate()
462461
{
463462
if(u)
464-
(u->currAllocator ? u->currAllocator : allocator ? allocator : getDefaultAllocator())->unmap(u);
465-
u = NULL;
463+
{
464+
UMatData* u_ = u;
465+
u = NULL;
466+
(u_->currAllocator ? u_->currAllocator : allocator ? allocator : getDefaultAllocator())->unmap(u_);
467+
}
466468
}
467469

468470
Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange)

modules/core/src/umatrix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ UMat::~UMat()
411411

412412
void UMat::deallocate()
413413
{
414-
u->currAllocator->deallocate(u);
414+
UMatData* u_ = u;
415415
u = NULL;
416+
u_->currAllocator->deallocate(u_);
416417
}
417418

418419

0 commit comments

Comments
 (0)