fix memory leak in VSliceAlloc
This commit is contained in:
33
deps/oblib/src/lib/allocator/ob_slice_alloc.h
vendored
33
deps/oblib/src/lib/allocator/ob_slice_alloc.h
vendored
@ -131,9 +131,11 @@ public:
|
||||
}
|
||||
public:
|
||||
uint32_t total() { return total_; }
|
||||
int32_t stock() { return stock_; }
|
||||
int32_t remain() { return stock_ > K ? stock_ - K : (stock_ < 0 ? stock_ + K : stock_); }
|
||||
bool acquire() { return dec_if_gt(K, K) > K; }
|
||||
bool release() { return faa(-K) > 0; }
|
||||
bool recyle() {
|
||||
bool recycle() {
|
||||
int32_t total = total_;
|
||||
return inc_if_lt(2 * K, -K + total) == -K + total;
|
||||
}
|
||||
@ -271,13 +273,37 @@ public:
|
||||
LIB_LOG(INFO, "ObSliceAlloc init finished", K(bsize_), K(isize_), K(slice_limit_), KP(tmallocator_));
|
||||
}
|
||||
~ObSliceAlloc() {
|
||||
tmallocator_ = NULL;
|
||||
destroy();
|
||||
}
|
||||
int init(const int size, const int block_size, BlockAlloc& block_alloc, const ObMemAttr& attr) {
|
||||
int ret = common::OB_SUCCESS;
|
||||
new(this)ObSliceAlloc(size, attr, block_size, block_alloc, NULL);
|
||||
return ret;
|
||||
}
|
||||
void destroy() {
|
||||
for(int i = MAX_ARENA_NUM - 1; i >= 0; i--) {
|
||||
Arena& arena = arena_[i];
|
||||
Block* old_blk = arena.clear();
|
||||
if (NULL != old_blk) {
|
||||
blk_ref_[ObBlockSlicer::hash((uint64_t)old_blk) % MAX_REF_NUM].sync();
|
||||
if (old_blk->release()) {
|
||||
blk_list_.add(&old_blk->dlink_);
|
||||
if (old_blk->recycle()) {
|
||||
destroy_block(old_blk);
|
||||
} else {
|
||||
_LIB_LOG(ERROR, "there was memory leak, stock=%d, remain=%d", old_blk->stock(), old_blk->remain());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ObDLink* dlink = nullptr;
|
||||
if (OB_NOT_NULL(dlink = blk_list_.top())) {
|
||||
Block* blk = CONTAINER_OF(dlink, Block, dlink_);
|
||||
_LIB_LOG(ERROR, "there was memory leak, stock=%d, remain=%d", blk->stock(), blk->remain());
|
||||
}
|
||||
tmallocator_ = NULL;
|
||||
bsize_ = 0;
|
||||
}
|
||||
void set_nway(int nway) {
|
||||
if (nway <= 0) {
|
||||
nway = 1;
|
||||
@ -351,6 +377,7 @@ public:
|
||||
Block* blk = item->host_;
|
||||
#ifndef NDEBUG
|
||||
abort_unless(blk->get_slice_alloc() == this);
|
||||
abort_unless(bsize_ != 0);
|
||||
#else
|
||||
if (this != blk->get_slice_alloc()) {
|
||||
LIB_LOG(ERROR, "blk is freed or alloced by different slice_alloc", K(this), K(blk->get_slice_alloc()));
|
||||
@ -391,7 +418,7 @@ private:
|
||||
}
|
||||
void add_to_blist(Block* blk) {
|
||||
blk_list_.add(&blk->dlink_);
|
||||
if (blk->recyle()) {
|
||||
if (blk->recycle()) {
|
||||
destroy_block(blk);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user