以下代码是在调用vector.erase(itr)时零星地转储核心。如果我在这里做错了,你能指出一下吗?
std::vector<Ntfy>::iterator itr = NtfyVector.begin();
for ( ; itr != NtfyVector.end(); )
{
if (certaion condition) {
itr = NtfyVector.erase(itr);
continue;
} else {
itr++;
}
}
以下是GDB跟踪:
(gdb)其中
#0 0x000000000048cea5在__gnu_cxx :: new_allocator :: destroy(这= 0x7f0890,__ p = 0x7adbbf0)/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../ ../包括/ C ++ / 4.1.2 / EXT / new_allocator.h:107
#1 0x000000000048da34 in std :: vector&gt; :: erase(this = 0x7f0890,__position = {_ M_current = 0x7adbc40}) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2 /../../../../ include / c ++ / 4.1.2 / bits / vector.tcc:115
我正在使用g ++(GCC)4.4.7 20120313(Red Hat 4.4.7-3)。
void NtfyHandle(void) {
std::vector<Ntfy>::iterator itr = NtfyVector.begin();
for ( ; itr != NtfyVector.end(); )
{
PF_BOOL bRetry = PF_FALSE;
switch (itr->GetOperation()) {
case PF_SERVICE_ADD:
{
bRetry = LISwithState(itr->GetServiceName(), itr->GetNewState(), itr->GetInvokeId());
}
break;
case PF_SERVICE_REM:
{
liPsPlatform->SendInvokeResponse(itr->GetInvokeId(), PF_STATUS_SUCCESS);
}
break;
default: break;
}
if (PF_FALSE == bRetry) {
// Delete the notification from the vector since retry isn't required
itr = NtfyVector.erase(itr);
continue;
} else {
itr++;
}
}
}
答案 0 :(得分:1)
似乎与给定的循环没有任何关系但是Ntfy :: ~Ntfy析构函数可能有问题? “擦除 - 删除”这个习惯用法允许有更多更整洁的代码。