3 ms·
I'm not seeing the segfault, but it does leak memory like a sieve with no filter. Good point re: age. ++head->age should be the first operation of the while lo
by fragmede 16y ago
I'm not seeing the segfault, but it does leak memory like a sieve with no filter.
Good point re: age. ++head->age should be the first operation of the while loop.
- jws 16y agoJust in case someone is scratching their head over this... Let's come into the while loop body with data like this where H is the head pointer, C and E are elements of the list... H -> C /* head points to current node */ C->next -> E /* expired node is next*/ E->next -> NULL /* expired node is last */ if ( head->next == NULL)... /* no, head points to C, C->next is E */ if ( head->next->age > EXP...) /* yes, head->next is E and is expired */ head->next = head->next->next /* C->next is now NULL (E->next) */ head = head->next; /* head is now NULL */ /* back to the top of the loop */ while( *head != NULL... /* BANG! a NULL value just got dereferenced */