libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
544 stars 305 forks source link

valgrind ? #123

Closed wishkind closed 5 years ago

wishkind commented 6 years ago

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!

void node_list_destroy(node_list_t* list) {
    if(list != NULL) {
        list_destroy((list_t*) list);  //here type conversion  any memory leak?
    }
}
wishkind commented 6 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;

nikias commented 5 years ago

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.

nikias commented 5 years ago

I think there is no memory leak here.