首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检测到堆损坏-仅限iPhone 5S

检测到堆损坏-仅限iPhone 5S
EN

Stack Overflow用户
提问于 2013-11-29 10:48:04
回答 3查看 4K关注 0票数 3

我正在开发一个用于监听频率/音高的应用程序,它在iPhone4s、模拟器和其他设备上工作得很好,但iPhone 5S却不行。这是我得到的信息:

代码语言:javascript
复制
malloc: *** error for object 0x178203a00: Heap corruption detected, free list canary is damaged

有什么建议我应该从哪里开始研究呢?

谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-11-30 17:25:06

iPhone 5s有一个臂64/64位CPU。检查所有用于尝试将64位指针(和其他值)存储到32位C数据类型中的分析编译器警告。

还要确保您的所有音频代码参数传递、对象消息传递和手动内存管理代码都是线程安全的,并且满足所有的实时要求。

票数 3
EN

Stack Overflow用户

发布于 2014-03-22 13:38:49

如果它对任何人有帮助的话,我遇到的问题和上面描述的完全一样。

在我的特殊情况下,原因是pthread_create(pthread_t*线程,.)在ARM64上,在线程启动后的某个时候将值放入*线程。在OSX、ARM32和模拟器上,在调用start_routine之前,它一直在填充这个值。

如果在写入该值之前在正在运行的线程中执行pthread_detach操作(即使使用pthread_self()获取当前thread_t),我将得到堆损坏消息。

我在线程调度程序中添加了一个小循环,直到填充了这个值--然后堆错误就消失了。别忘了“不稳定”!

重构代码可能是修复这个问题的更好方法--这取决于您的情况。(我在我编写的单元测试中注意到了这一点,我没有在任何“真正的”代码上跳过这个问题)

票数 2
EN

Stack Overflow用户

发布于 2021-01-15 01:39:42

同样的问题。但我的例子是我的malloc 10字节内存,但我尝试使用20字节。然后它就会滋生腐败。

代码语言:javascript
复制
@@ -64,7 +64,7 @@ char* bytesToHex(char* buf, int size) {
         * be converted to two hex characters, also add an extra space for the terminating
         * null byte.
         * [size] is the size of the buf array */
-       int len = (size * 2) + 1;
+       int len = (size * 3) + 1;
        char* output = (char*)malloc(len * sizeof(char));
        memset(output, 0, len);
        /* pointer to the first item (0 index) of the output array */
    char *ptr = &output[0];
    int i;
    for (i = 0; i < size; i++) {
        /* "sprintf" converts each byte in the "buf" array into a 2 hex string
         * characters appended with a null byte, for example 10 => "0A\0".
         *
         * This string would then be added to the output array starting from the
         * position pointed at by "ptr". For example if "ptr" is pointing at the 0
         * index then "0A\0" would be written as output[0] = '0', output[1] = 'A' and
         * output[2] = '\0'.
         *
         * "sprintf" returns the number of chars in its output excluding the null
         * byte, in our case this would be 2. So we move the "ptr" location two
         * steps ahead so that the next hex string would be written at the new
         * location, overriding the null byte from the previous hex string.
         *
         * We don't need to add a terminating null byte because it's been already
         * added for us from the last hex string. */
        ptr += sprintf(ptr, "%02X ", buf[i] & 0xFF);
    }
    return output;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20283947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档