Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检测到堆损坏-仅限iPhone 5S_Ios_Objective C_Audio_Core Audio - Fatal编程技术网

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

Ios 检测到堆损坏-仅限iPhone 5S,ios,objective-c,audio,core-audio,Ios,Objective C,Audio,Core Audio,我正在开发一款可以监听频率/音调的应用程序,它在iPhone4s、模拟器和其他设备上运行良好,但在iPhone5S上却不行。这是我得到的信息: malloc: *** error for object 0x178203a00: Heap corruption detected, free list canary is damaged 有什么建议我应该从哪里开始深入研究 谢谢 iPhone 5s有一个arm64/64位CPU。检查所有分析编译器警告,以尝试将64位指针(和其他值)存储到32位C数

我正在开发一款可以监听频率/音调的应用程序,它在iPhone4s、模拟器和其他设备上运行良好,但在iPhone5S上却不行。这是我得到的信息:

malloc: *** error for object 0x178203a00: Heap corruption detected, free list canary is damaged
有什么建议我应该从哪里开始深入研究


谢谢

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


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

如果它对任何人都有帮助,我遇到的问题与上述问题完全相同

在我的特殊情况下,原因是ARM64上的pthread_create(pthread_t*thread,…)在线程启动后的某个时间将值放入*thread。在OSX、ARM32和模拟器上,在调用start_例程之前,它始终填充此值

如果在写入该值之前在正在运行的线程中执行pthread_detach操作(甚至使用pthread_self()获取当前线程),则最终会出现堆损坏消息

我在我的线程调度程序中添加了一个小循环,等待该值被填充,然后堆错误消失。别忘了“挥发性”


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

同样的问题。但我的情况是我使用10字节内存,但我尝试使用20字节。然后它会导致腐败

@@ -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;

@-64,7+64,7@@char*bytesToHex(char*buf,int-size){
*如果要转换为两个十六进制字符,还需要为终止字符添加额外的空间
*空字节。
*[size]是buf阵列的大小*/
-整数长度=(大小*2)+1;
+整数长度=(大小*3)+1;
char*output=(char*)malloc(len*sizeof(char));
memset(输出,0,len);
/*指向输出数组的第一项(0索引)的指针*/
char*ptr=&输出[0];
int i;
对于(i=0;i“0A\0”。
*
*然后,该字符串将从
*“ptr”指向的位置。例如,如果“ptr”指向0
*然后索引“0A\0”将被写入输出[0]=“0”、输出[1]=“A”和
*输出[2]='\0'。
*
*“sprintf”返回其输出中的字符数,不包括空字符
*字节,在我们的例子中是2。所以我们把“ptr”位置移到2
*前进一步,以便在新的位置写入下一个十六进制字符串
*位置,重写上一个十六进制字符串中的空字节。
*
*我们不需要添加终止的空字节,因为它已经被终止了
*从最后一个十六进制字符串为我们添加*/
ptr+=sprintf(ptr,“%02X”,buf[i]&0xFF);
}
返回输出;

损坏可能是在5s上检测到的设备上。搜索malloc_调试库,您可以使用该库查找问题。