ios malloc:*** 错误:已释放对象的校验和不正确 - 对象可能在被释放后被修改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19840671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:48:48  来源:igfitidea点击:

malloc: *** error: incorrect checksum for freed object - object was probably modified after being freed

iosobjective-cccrashmalloc

提问by Pedro Soares

I have a big problem with my iOS App: it crashes sometimes without detailed debug error. The stack trace is empty. These are the only two lines in the stack trace:

我的 iOS 应用程序有一个大问题:它有时会在没有详细调试错误的情况下崩溃。堆栈跟踪是空的。这些是堆栈跟踪中仅有的两行:

  1. crash start in UIApplicationMain at "symbol stub for: -[_UIHostedTextServiceSession dismissTextServiceAnimated:]".
  2. and report "libsystem_c.dylib`malloc_error_break".
  1. 崩溃开始在 UIApplicationMain 的“符号存根:-[_UIHostedTextServiceSessiondismissTextServiceAnimated:]”。
  2. 并报告“libsystem_c.dylib`malloc_error_break”。

in com.apple.main-thread.

com.apple.main-thread

The error on Xcode debugger (with connected device):

Xcode 调试器上的错误(连接设备):

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

I have set a breakpoint in malloc_error_break with libsystem_c.dylib without any feedback from debugger. I have no idea to solve this issue.

我用 libsystem_c.dylib 在 malloc_error_break 中设置了一个断点,没有来自调试器的任何反馈。我不知道解决这个问题。

回答by Pedro Soares

To find the source of the problem, in Xcode go to Product > Scheme > Edit Scheme, and under Diagnostics tab enable all the Malloc settings and Guard Malloc.

要找到问题的根源,在 Xcode 中转到 Product > Scheme > Edit Scheme,然后在 Diagnostics 选项卡下启用所有 Malloc 设置和 Guard Malloc。

With that, run your application again, and Xcode will stop at the line causing the problem.

这样,再次运行您的应用程序,Xcode 将停在导致问题的行处。

Scheme definition

方案定义

回答by user1118321

Since you're in the debugger, you should look at the memory location 0x208a7614and see what's there. The data in memory may be helpful in figuring out what's going wrong.

由于您在调试器中,您应该查看内存位置0x208a7614,看看那里有什么。内存中的数据可能有助于找出问题所在。

What's happening is one of the following:

发生的情况是以下情况之一:

  1. you are freeing an object twice,

  2. you are freeing a pointer that was never allocated

  3. you are writing through an invalid pointer which previously pointed to an object which was already freed

  1. 你要释放一个对象两次,

  2. 你正在释放一个从未分配过的指针

  3. 您正在通过一个无效的指针写入,该指针以前指向一个已经被释放的对象

Since the stack trace is coming up empty, it might be useful to add some debugging log statements to your code at various places to see if you can narrow down where in the code the problem lies. Using the memory tools in Instruments might also help. You could try turning on NSZombies, but this looks like a C allocation problem and not an Objective-C one.

由于堆栈跟踪变为空,因此在不同位置向代码添加一些调试日志语句可能会很有用,以查看是否可以缩小代码中问题所在的范围。使用 Instruments 中的记忆工具也可能有所帮助。您可以尝试打开 NSZombies,但这看起来像是 C 分配问题,而不是 Objective-C 问题。

Also, is anything else written to the console before the crash? If so, it may point you to where the problem is coming from.

另外,在崩溃之前是否还有其他内容写入控制台?如果是这样,它可能会指出问题的来源。

回答by Ravi Raja Jangid

hi guys i have found this solution if you are using nib or xib interface and you facing this problem when you want to push a viewcontroller object then some time this error will occur and your app will be crash (specially error in iPad) Here is the solution:

嗨,伙计们,我找到了这个解决方案,如果您使用的是 nib 或 xib 接口,并且当您想推送一个视图控制器对象时遇到这个问题,那么有时会发生此错误并且您的应用程序将崩溃(特别是 iPad 中的错误)解决方案:

// Format like this

// 格式如下

UINavigationController *nav=[[UINavigationController      alloc]initWithRootViewController:yourViewControllerObj];

[self.navigationController  presentViewController:nav animated:true completion:nil];

Don't try to push in this condition.

不要试图在这种情况下推动。

回答by MK Islam

If you have this problem. go to: product->scheme->diagnosis-> then enable mollic gaurd edgeand zombie objectthen close then go product->stop then again product-build and run. best ofluck

如果你有这个问题。去:产品->方案->诊断->然后启用mollic gaurd边缘僵尸对象然后关闭然后去产品->停止然后再次产品构建并运行。祝你好运