'corrupt value'在 iOS 上意味着什么?



我在我的iOS应用程序上编写c++。当我调用v->assign(anotherVec.begin(), anotherVec.end())时,它总是显示malloc: Incorrect checksum for freed object 0x7fe87824ea00: probably modified after being freed. Corrupt value: 0x0v是一个vector<double>指针,崩溃前向量大小为0。anotherVec也是vector<double>,它的大小是208。每次释放的对象地址都不同。应用程序内存似乎足够。

这是崩溃函数和STL矢量中的位置,我粘贴这个只是为了显示它在STL代码中崩溃的位置:

template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_cpp17_forward_iterator<_ForwardIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_ForwardIterator>::reference>::value,
void
>::type
vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__new_size <= capacity())
{
_ForwardIterator __mid = __last;
bool __growing = false;
if (__new_size > size())
{
__growing = true;
__mid =  __first;
_VSTD::advance(__mid, size());
}
pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
if (__growing)
__construct_at_end(__mid, __last, __new_size - size());
else
this->__destruct_at_end(__m);
}
else
{
__vdeallocate();
__vallocate(__recommend(__new_size));              // Crashes here!!!!!!
__construct_at_end(__first, __last, __new_size);
}
__invalidate_all_iterators();
}

我用Apple Clang 12.0运行这个。X和13.0。x, Xcode。我的编译选项是-Os --std=c++11 -fPIC -pthread -fno-exceptions。在我们的用户中,这种情况发生在0.01%左右,不同的数据,iphone和iOS版本。

我的macOS版本是12.1

所以我想知道:

  1. Corrupt value: 0x0是什么意思?我已经搜索了几个小时,但没有找到任何解释。
  2. 是否有办法监控哪个代码访问或修改某个内存地址?以及如何?
  3. 我还能做些什么来处理这个崩溃?因为我不能做一个最小的可重复的例子,我只是要求思路或工具来分析。

地址消毒液就是这样一个锋利的工具。在我孤立的演示应用程序上使用它,它显示了几个内存问题,其中一个是anotherVec可能在某些情况下导致索引超出界限的问题。随着它的修复,assign崩溃消失了。修复了所有问题后,我们在模块中收集的崩溃将无法在主应用程序中重现。

ASan我甚至发现更多的问题与其他模块在我的应用程序。我宣布我的同事关于他们,它也修复了他们的崩溃。

然而,我仍然没有找到Corrupt value: 0x0是什么意思。欢迎任何信息,非常感谢!

最新更新