support asan in 3.1_opensource_release

This commit is contained in:
xy0
2022-04-08 14:00:52 +08:00
committed by LINxiansheng
parent 021cb19e6c
commit e43242fe44
4 changed files with 70 additions and 60 deletions

View File

@ -19,7 +19,7 @@ using namespace common;
namespace oceanbase {
namespace blocksstable {
ObSelfBufferWriter::ObSelfBufferWriter(const int64_t size, const char* label, const bool need_align)
ObSelfBufferWriter::ObSelfBufferWriter(const int64_t size, const char *label, const bool need_align)
: ObBufferWriter(NULL, 0, 0), label_(label), is_aligned_(need_align), macro_block_mem_ctx_()
{
int ret = OB_SUCCESS;
@ -39,11 +39,11 @@ ObSelfBufferWriter::~ObSelfBufferWriter()
macro_block_mem_ctx_.destroy();
}
char* ObSelfBufferWriter::alloc(const int64_t size)
char *ObSelfBufferWriter::alloc(const int64_t size)
{
char* data = NULL;
char *data = NULL;
if (size == macro_block_mem_ctx_.get_block_size()) {
data = (char*)macro_block_mem_ctx_.alloc();
data = (char *)macro_block_mem_ctx_.alloc();
if (OB_ISNULL(data)) {
STORAGE_LOG(WARN, "fail to alloc buf from mem ctx", K(size));
}
@ -52,9 +52,9 @@ char* ObSelfBufferWriter::alloc(const int64_t size)
// alloc from mem ctx fail
if (OB_ISNULL(data)) {
if (is_aligned_) {
data = (char*)ob_malloc_align(BUFFER_ALIGN_SIZE, size, label_);
data = (char *)ob_malloc_align(BUFFER_ALIGN_SIZE, size, label_);
} else {
data = (char*)ob_malloc(size, label_);
data = (char *)ob_malloc(size, label_);
}
}
return data;
@ -79,7 +79,7 @@ int ObSelfBufferWriter::ensure_space(int64_t size)
}
} else if (capacity_ < size) {
// resize;
char* new_data = NULL;
char *new_data = NULL;
if (NULL == (new_data = alloc(size))) {
STORAGE_LOG(WARN, "allocate buffer memory error.", K(size));
ret = OB_ALLOCATE_MEMORY_FAILED;
@ -97,17 +97,21 @@ int ObSelfBufferWriter::ensure_space(int64_t size)
void ObSelfBufferWriter::free()
{
if (NULL != data_) {
#ifndef OB_USE_ASAN
if (macro_block_mem_ctx_.get_allocator().contains(data_)) {
macro_block_mem_ctx_.free(data_);
} else {
data_ = NULL;
}
#endif
if (NULL != data_) {
if (is_aligned_) {
ob_free_align(data_);
} else {
ob_free(data_);
}
data_ = NULL;
}
}
data_ = NULL;
}
} // namespace blocksstable
} // namespace oceanbase