gpt4 book ai didi

c - 段错误 - 无效指针

转载 作者:太空宇宙 更新时间:2023-11-04 08:45:42 25 4
gpt4 key购买 nike

我附上了一个片段。我省略了很多。如果需要,我会附上更多:

 unsigned char *datap = malloc (MAXSIZE);
unsigned char *datapor = datap;
//Here Im cutting a lot
while( (direntp = readdir(dirp)) != NULL)
{
datap = datapor;
}
//this line gives me exception
free(datap);

gcc 显示:

*** glibc detected *** /home/xf/xf/unzipper: free(): invalid pointer: 0x00002aaaab0b0108 ***

最佳答案

您在 while 循环中重新分配 datap,因此当您调用 free 时,datap 不再指向分配的内存。

(我假设 datapor 的值在省略的代码中发生了变化。)

关于c - 段错误 - 无效指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21756772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com