C - Unable to free doubly linked list node -


i have data structure this:

typedef struct telephonebooknode {     int id;     char name[name_length];     char telephone[telephone_length];     struct telephonebooknode * previousnode;     struct telephonebooknode * nextnode; } telephonebooknode;  typedef struct telephonebooklist {     telephonebooknode * head;     telephonebooknode * tail;     telephonebooknode * current;     unsigned size; } telephonebooklist; 

i can create nodes, , make list containing data because got no problems in displaying list, inserting or moving nodes....

but when write function erase list, got error:

phonebook(6187,0x7fff77045000) malloc: *** error object 0x7f87c1f00004: pointer being freed not allocated *** set breakpoint in malloc_error_break debug 

this eraser functions:

void freetelephonebooklist(telephonebooklist* alist) {     telephonebooknode* node;     telephonebooknode* temp = alist->head;      while (temp) {         node = temp;         temp = node->nextnode;         freetelephonebooknode(node);     }     free(alist); }  void freetelephonebooknode(telephonebooknode * node) {     free(node->name);     free(node->telephone);     free(node); } 

please tells me have been doing wrong here. thank you!

note anwer relates initial version of question.

variables node->name , node->telephone not pointers separate allocated blocks of memory, they're parts of *node. reduce freetelephonebooknode function to

void freetelephonebooknode(telephonebooknode * node) {     free(node); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -