【发布时间】:2011-12-15 05:58:38
【问题描述】:
我有链接列表,其节点结构如下所示
struct node
{
char *p;
struct node *next;
}*start;
现在我们 char *p 是指向由 malloc 调用分配的内存位置的指针。同样,整体也是使用 malloc 分配的。现在想释放两个 malloc 调用占用的空间,如下所示
main()
{
struct node *tmp;
tmp=malloc(sizeof(struct node));
tmp->next=NULL;
tmp->p=malloc(2*sizeof(int));
free(tmp->p);
free(tmp);
}
这是释放内存的正确方法还是这里需要什么?
【问题讨论】:
标签: c linked-list