Closed wishkind closed 5 years ago
void list_init(list_t* list) {
list->next = NULL;
list->prev = list;
}
node_list_t* node_list_create() {
node_list_t* list = (node_list_t*) malloc(sizeof(node_list_t));
if(list == NULL) {
return NULL;
}
memset(list, '\0', sizeof(node_list_t));
// Initialize structur
list_init((list_t*) list);
list->count = 0;
return list;
}
i think it just very simple, as below:
node_list_t *node_list_init() {
struct _node_list_t *list = je_malloc(sizeof(struct _node_list_t));
list->count = 0;
list->begin = NULL;
list->end = NULL;
return list;
}
why do you make so difficult? i can not understand list_init(list_t *) list); list->prev = list;
Hi, this is because initially all the list logic stuff was supposed to go into list.c/h but it actually got implemented in node_list.c. I pushed commit bec850fe399639f3b8582a39386216970dea15ed that removes list.c+list.h completely.
I think there is no memory leak here.
sizeof(struct node_list_t ) = 32, sizeof(struct list_t) = 16. the following free memory , convert type ,memory leak? only 16bytes free, left 16bytes not free. My doubt!