1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

core(buffer_area): handle 'OPENCV_ENABLE_MEMORY_SANITIZER=ON' case

This commit is contained in:
Alexander Alekhin
2020-03-16 19:34:08 +03:00
parent 8f49b820db
commit 77d1c20fb7
2 changed files with 32 additions and 10 deletions
+26 -10
View File
@@ -5,14 +5,10 @@
#include "opencv2/core/utils/buffer_area.private.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
#ifdef OPENCV_ENABLE_MEMORY_SANITIZER
#define BUFFER_AREA_DEFAULT_MODE true
#else
#define BUFFER_AREA_DEFAULT_MODE false
#endif
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
static bool CV_BUFFER_AREA_OVERRIDE_SAFE_MODE =
cv::utils::getConfigurationParameterBool("OPENCV_BUFFER_AREA_ALWAYS_SAFE", BUFFER_AREA_DEFAULT_MODE);
cv::utils::getConfigurationParameterBool("OPENCV_BUFFER_AREA_ALWAYS_SAFE", false);
#endif
namespace cv { namespace utils {
@@ -58,6 +54,7 @@ public:
*ptr = raw_mem;
}
}
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
void * fast_allocate(void * buf) const
{
CV_Assert(ptr && *ptr == NULL);
@@ -66,6 +63,7 @@ public:
*ptr = buf;
return static_cast<void*>(static_cast<uchar*>(*ptr) + type_size * count);
}
#endif
bool operator==(void **other) const
{
CV_Assert(ptr && other);
@@ -86,12 +84,20 @@ private:
//==================================================================================================
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
BufferArea::BufferArea(bool safe_) :
oneBuf(0),
totalSize(0),
safe(safe_ || CV_BUFFER_AREA_OVERRIDE_SAFE_MODE)
{
// nothing
}
#else
BufferArea::BufferArea(bool safe_)
{
CV_UNUSED(safe_);
}
#endif
BufferArea::~BufferArea()
{
@@ -101,10 +107,16 @@ BufferArea::~BufferArea()
void BufferArea::allocate_(void **ptr, ushort type_size, size_t count, ushort alignment)
{
blocks.push_back(Block(ptr, type_size, count, alignment));
if (safe)
blocks.back().real_allocate();
else
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
if (!safe)
{
totalSize += blocks.back().getByteCount();
}
else
#endif
{
blocks.back().real_allocate();
}
}
void BufferArea::zeroFill_(void **ptr)
@@ -129,6 +141,7 @@ void BufferArea::zeroFill()
void BufferArea::commit()
{
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
if (!safe)
{
CV_Assert(totalSize > 0);
@@ -141,6 +154,7 @@ void BufferArea::commit()
ptr = i->fast_allocate(ptr);
}
}
#endif
}
void BufferArea::release()
@@ -150,11 +164,13 @@ void BufferArea::release()
i->cleanup();
}
blocks.clear();
#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
if (oneBuf)
{
fastFree(oneBuf);
oneBuf = 0;
}
#endif
}
//==================================================================================================