64位版本的OSX - 不一致的malloc的错误 [英] 64-bit build in OSX - inconsistant malloc error

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

问题描述

我收到了非常不一致的错误在X code:

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

我知道,这不是我的$ C $直接C,因为一个32位版本的工作得很好(建筑设置为标准的32/64和建立有效的体系结构仅设置为NO)。它也偶尔会工作得很好,没有我改变甚至评论,但只有约的时间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.

我已经使用断点跟踪误差,有时它发生在像伊娃:MyClass的=新MyClass的,但有时它发生在删除一个不相关的伊娃。我试过设置myClass的前新实例创建为空,但没有帮助,我很茫然,因为我不完全理解缓存,寄存器堆,和堆栈(这可能会给了解为什么发生这种情况)。

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).

下面是一些code。在我得到了错误的地方。请注意,每个组的code线的是一个不同的地方,和类,其中,误差可能,也可能不,发生

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);
}

这可能指向解决方案的任何想法会大大AP preciated。

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

GW

推荐答案

您需要添加一个断点建议的功能 malloc_error_break()。运行该应用程序,然后让该函数的调试突破。退一步一个或两个堆栈帧,你会看到哪些变量操作系统认为已被释放,你已经修改。然后你需要找出其中的变量可能是previously中解脱出来。

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 ED块,然后写信给你意外地写了几个字节的的该 malloc的指针返回。你可以赶上通过开启<一href="https://developer.apple.com/library/mac/#releasenotes/DeveloperTools/RN-MallocOptions/_index.html"相对=nofollow>后卫的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.

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

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