【发布时间】:2022-06-14 20:43:48
【问题描述】:
p1 指针用于其他功能,没有任何变化。并且当不再需要调用 free_stuffs 函数但调用 free_stuffs 时,我得到双重释放或损坏(out) 中止(核心转储)
char **someFunction(){
const char ** p1 = (char **)malloc(total * sizeof(char *));
for (int i = 0; i <= total; i++){
*(p1 + i) = (char *)malloc(len * sizeof(char) +1);
}
return p1;
}
void free_stuffs(char ** p1){
for (int i = 0; i <= total; i++){
free(p1[i]);
}
free(p1);
}
【问题讨论】:
-
请发Minimal, Reproducible Example,包括函数的调用者。