早上好-
valgrind 说:
==9735== 24,976 bytes in 446 blocks are definitely lost in loss record 9 of 9
==9735== at 0x100012362: malloc (vg_replace_malloc.c:266)
==9735== by 0x1000016F2: interpolate (in ./a.out)
==9735== by 0x100000CFA: main (in ./a.out)
哎呀。这是我的插值函数:
void interpolate(PDouble* evaluated, int doubleCount){
int i, j, k;
int boxCount = 0;
int frameCount = 0;
for(i=0; i<doubleCount; i++){
boxCount = evaluated[i]->first->numBoxes;
frameCount = evaluated[i]->gap;
evaluated[i]->changeMatrix = (int***)malloc(boxCount*sizeof(int**));
for(j=0; j < boxCount; j++){
evaluated[i]->changeMatrix[j] = (int **)malloc(ATTR * sizeof(int*));
for(k=0; k < ATTR; k++){
evaluated[i]->changeMatrix[j][k] = (int*)malloc(sizeof(int)*frameCount);
if(evaluated[i]->differenceMatrix[j][k] > 200 ||
evaluated[i]->differenceMatrix[j][k] < -200){
generateRotationSequence(evaluated[i]->changeMatrix[j][k],
evaluated[i]->first->boxes[j]->o,
evaluated[i]->second->boxes[j]->o,
frameCount);
}
else{
evaluated[i]->changeMatrix[j][k] = (int*)malloc(sizeof(int)*frameCount);
generateSequence(evaluated[i]->changeMatrix[j][k],
evaluated[i]->differenceMatrix[j][k], frameCount);
}
}
}
}
}
但是我有 C 函数可以释放 PDoubles 的所有指针。如果需要,我可以提供代码,但是有什么明显的地方会导致它泄漏或指针悬空吗?
编辑:意识到我在描述中使用了一个奇怪的术语。这次我也添加了我的析构函数
void killDouble(PDouble marked){
int i, j, k;
int gap = marked->gap;
for(i=0; i < marked->first->numBoxes; i++){
for(j=0; j < ATTR; j++){
free(marked->changeMatrix[i][j]);
}
free(marked->changeMatrix[i]);
free(marked->differenceMatrix[i]);
}
for(i=0; i < gap; i++){
killFrame(marked->intFrames[i]);
}
killFrame(marked->first);
killFrame(marked->second);
free(marked->changeMatrix);
free(marked->differenceMatrix);
free(marked->intFrames);
free(marked);
}