Func1 用来create 一个指针数组。每个指针指向一个struct node myNode
void Func1 (myNode*** p)
{
// len is a global value
myNode** tmp;
tmp = (myNode**) malloc(sizeof(myNode*) * len);
p = &tmp;
……
for (int i=0; i
{
(*p)[i] = (myNode*)malloc(sizeof(myNode));
……
}
}
Func2用来处理这个指针数组和回收memory
void Func2 (void)
{
myNode** p;
Func1 (&p);
for (int i=0; i
{
if (p[i])
{
// Handle data
free (p[i]);
}
}
free (p);
}
Questions
d****p 发帖数: 685
2
this is wrong. tmp is an auto var and becomes garbage once Func1 finishes.So
p will be pointing to garbage.
In this case p may happen to have correct value but that will change once
you insert a lot of lines between calling Func1 and dereferencing p.