struct node {
int footpath_id;
double deltaz;
char* address;
char* clue_sa;
};
struct dict {
struct node record;
struct dict* next;
};
结构体释放时实体变量int
、double
之类会一起释放掉,但char*
指针不会,因此需要先释放掉char*
指针再释放结构体。
这是释放结构体链表内存的代码
void free_dict(struct dict* dict1) {
struct dict* now = dict1;
struct dict* nx;
while (now != NULL) {
nx = now;
now = now->next;
free_node(nx->record);
free(nx);
}
dict1 = NULL;
}
void free_node(struct node record) {
free(record.address);
free(record.clue_sa);
}