I believe you're wiping out the head without replacing it when you call remove_node(&head), thus causing all your grief.
Code:
void remove_node(struct job_node **job) {
if(*job == NULL) // head isn't NULL, ok so far
return;
if((*job)->prev != NULL) // head->prev should be NULL, still ok
(*job)->prev->next = (*job)->next;
if((*job)->next != NULL) // head->next != NULL, so lets do this
(*job)->next->prev = (*job)->prev; // next->prev is set to NULL (since head doesn't have a prev)
free_job_node(job); // head gets freed
*job = NULL; // wuh oh... head never got replaced
}
Ok the following code works for me (using his original code and all fixes mentioned earlier) and correctly removes the head from the list. Can anyone confirm?
Code:
void remove_node(struct job_node **job) {
if(*job == NULL)
return;
if((*job)->next != NULL)
(*job)->next->prev = (*job)->prev;
if((*job)->prev != NULL)
(*job)->prev->next = (*job)->next;
else { // if this node doesn't have a prev, then it must be the head!
struct job_node *tmp = (*job)->next;
free_job_node(job);
*job = tmp;
return;
}
free_job_node(job);
*job = NULL;
}
Oh btw, I also typedef'd pid_t to int (I didn't see it defined anywhere)