Deallocation in cv::Mat of externally allocated memory (Bug #2799)
Description
Behaviour is changed since previous version.
Is it correct, that opencv could delete memory pointer, allocated somewhere outside the library?
I have noticed that when I use this c-tor:
cv::Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0)
In stock 2.4.3, where data is pointer to some memory allocated before. Then, when cv::Mat
will be destroyed, data will be deallocated (in my case only try to deallocate)
void Mat::deallocate() { if( allocator ) allocator->deallocate(refcount, datastart, data); else { CV_DbgAssert(refcount != 0); fastFree(datastart); } }
I think in this case (allocator==0, OpenCV does not own the memory) fastFree
call is incorrect.
Associated revisions
Merge pull request #2799 from 23pointsNorth:patch-1
History
Updated by Kirill Kornyakov about 12 years ago
Good question, but please format your description properly next time (use pre
tag and proper case).
Vadim, what are your thoughts?
- Category set to core
- Assignee set to Vadim Pisarevsky
- Subject changed from Deallocation in cv::Mat of non opencv data to Deallocation in cv::Mat of externally allocated memory
- Description changed from Behaviour is changed since previous version. Is it correct, that opencv coul... to Behaviour is changed since previous version. Is it correct, that opencv coul... More
Updated by Michael Lou almost 12 years ago
Happened to find this bug report. In my opinion, this should not be a problem.
In the case when matrix points to user-allocated data, the refcount
pointer is NULL
.
Therefore, the destructor would not call deallocate()
function.
Mat::~Mat() { release(); if( step.p != step.buf ) fastFree(step.p); }
void Mat::release() { if( refcount && CV_XADD(refcount, -1) == 1 ) deallocate(); data = datastart = dataend = datalimit = 0; size.p[0] = 0; refcount = 0; }
Evgeny Elkin wrote:
Behaviour is changed since previous version.
Is it correct, that opencv could delete memory pointer, allocated somewhere outside the library?
I have noticed that when I use this c-tor:
[...]
In stock 2.4.3, where data is pointer to some memory allocated before. Then, when
cv::Mat
will be destroyed, data will be deallocated (in my case only try to deallocate)[...]
I think in this case (allocator==0, OpenCV does not own the memory)
fastFree
call is incorrect.
Updated by Andrey Pavlenko over 11 years ago
- Status changed from Open to Cancelled
- Affected version changed from 2.4.3 to 2.4.0 - 2.4.4
- Start date deleted (
2013-02-14)