-
Notifications
You must be signed in to change notification settings - Fork 119
Open
Description
若线程一执行到allocateNewBlock函数中freeList_ = nullptr;语句前,线程二释放了某个槽的空间,并修改了freeList_,线程一执行freeList_ = nullptr后,会导致逻辑上内存泄漏。
`
void* newBlock = operator new(BlockSize_);
reinterpret_cast<Slot*>(newBlock)->next = firstBlock_;
firstBlock_ = reinterpret_cast<Slot*>(newBlock);
char* body = reinterpret_cast<char*>(newBlock) + sizeof(Slot*);
size_t paddingSize = padPointer(body, SlotSize_); // 计算对齐需要填充内存的大小
curSlot_ = reinterpret_cast<Slot*>(body + paddingSize);
// 超过该标记位置,则说明该内存块已无内存槽可用,需向系统申请新的内存块
lastSlot_ = reinterpret_cast<Slot*>(reinterpret_cast<size_t>(newBlock) + BlockSize_ - SlotSize_ + 1);
freeList_ = nullptr;
`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels