void destroyList(list l,void (*destroyFunc)(void*)) { NODELISTPTR aux = l->head; while (aux) { //debug(); //printf("%s\n",((reference*)(aux->element))) destroyFunc(aux->element); free(aux); aux=aux->next; //aux2=NULL; }; free(l); l=NULL; }
// Destroying a whole list, calling function with pointer dfAdrr and passing pointer to pointer to element // If passing NULL function pointer element will not be cleaned void destroyList( list** l, void* dfAdrr ){ void (*destroyFunc)( char** ); destroyFunc = dfAdrr; list* cur = NULL; list* next = getListFirst( *l ); while( next != NULL ){ cur = next; next = next->next; //Calling destroy function for element within list node if( destroyFunc != NULL ){ destroyFunc( &cur->element ); } // Freeing malloc'ed memory free( cur ); } // Set to NULL list pointer *l = NULL; }