OSX 中的 64 位构建 - 不一致的 malloc 错误 [英] 64-bit build in OSX - inconsistant malloc error

查看:17
本文介绍了OSX 中的 64 位构建 - 不一致的 malloc 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 中遇到一个非常不一致的错误:

I'm getting a very inconsistant error in Xcode:

malloc: *** error for object 0x1041146f8: incorrect checksum for freed object - object was probably modified after being freed. *** set a breakpoint in malloc_error_break to debug

我知道这不是我的直接代码,因为 32 位构建工作得很好(体系结构设置为标准 32/64,仅构建活动体系结构设置为否).它偶尔也能正常工作,我什至不更改评论,但只有大约 %10 的时间.

I know that it's not my code directly because a 32-bit build works just fine (Architecture set to Standard 32/64 and Build Active Architectures Only is set to No). It also will occasionally work just fine without me changing even a comment, but only about %10 of the time.

我使用断点跟踪错误,有时它发生在一个 ivar 上,例如:myClass = new MyClass,但有时它发生在删除一个不相关的 ivar 上.我已经尝试在创建新实例之前将 myClass 设置为 null 但这没有帮助,而且我不知所措,因为我不完全了解缓存、寄存器、堆和堆栈(这可能会深入了解为什么这正在发生).

I've traced the error using breakpoints, sometimes it happens on an ivar like: myClass = new MyClass, but sometimes it happens on deleting an unrelated ivar. I've tried setting myClass to null prior to the new instances creation but that didn't help, and I'm at a loss because I don't completely understand caching, registers, heaps, and stacks (which may give insight into why this is happening).

这是我遇到错误的地方的一些代码.请注意,每组代码行都是不同的位置和类别,错误可能会发生,也可能不会发生.

Here's some of the code in the places I'm getting the error. Note that each set of lines of code is a different place, and class, where the error may, or may not, happen.

错误 1

void functionA() {
    // bunch of unrelated code
    if (aAinterpFilter)
        delete aAinterpFilter;

    // this is where the first error sometimes happens
    aAinterpFilter = new InterpFilter((Window::Sinc::LP*)filterDesign, aAinterpFactor);
}

错误 2

Window::Sinc::LP::~LP ()
{
    // the z delete is where the error sometimes happens
    delete[] z;
    delete[] kernel;
}

错误 3

void AAOsc :: setPhase(double phase) {
    if (phase < 0.0) phase = 0.0;
    if (phase > 1.0) phase = 1.0;

    // this is where the error rarely happens, but it does sometimes.
    osc->tickInfo->curvPhase = static_cast<uint>(phase * 4294967296.0);
}

任何可能指向解决方案的想法将不胜感激.

Any ideas that may point to the solution will be greatly appreciated.

GW

推荐答案

您需要在建议的函数 malloc_error_break() 上添加断点.运行应用程序并让调试器中断该函数.后退一两个堆栈帧,您将看到操作系统认为已释放的变量已被您修改.然后,您需要找出该变量之前可能已被释放的位置.

You need to add a breakpoint on the suggested function malloc_error_break(). Run the app and let the debugger break on that function. Step back a stack frame or two and you'll see which variable the OS thinks has been freed that you've modified. You then need to figure out where that variable may have been previously freed.

如果你有一块内存,你malloc编辑然后写入,并且你不小心在的指针之前写了几个字节,也会发生这种情况.malloc 返回.您可以通过打开 guard malloc 并让它再次发生.

This could also happen if you have a block of memory that you malloced and then write to and you accidentally write a few bytes before the pointer that malloc returned. You can catch that by turning on guard malloc and making it happen again.

这篇关于OSX 中的 64 位构建 - 不一致的 malloc 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆