0
我的问题是我必须释放一个双指针。我已经试过了:不能释放双指针
char** files = malloc(sizeof(char*) * files_int);
for(i=1; i <= files_int ; i++)
{
files[i] = malloc(500);
//fill with data...
}
//call function with needs the double pointer
functionA(files);
//free first array
for(x=1; x <= max_files ; x++){
free(files[x]);
}
//free second array
free(files);
我总是得到glibc检测到双免费或腐败(出)错误。
我在做什么错?
'files [files_int]'不存在。你忽略了'files [0]' – pmg
你应该为你的for语句执行'for(int x = 0; x
您正在使用基于1的索引。你应该使用基于0的。目前你正在脱离阵列的末尾。 – Dave