2008-07-17 22:46:57

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH] sm-notify: perform DNS lookup in the background.

On Thursday July 17, [email protected] wrote:
> >
> >> @@ -349,7 +364,6 @@ notify_host(int sock, struct nsm_host *host)
struct addrinfo *hold = host->ai;
struct addrinfo **next = &host->ai;
*next = hold->ai_next;
> >> while ( *next )
> >> next = & (*next)->ai_next;
> >> *next = hold;
> >> - hold->ai_next = NULL;
> >> memcpy(&host->addr, hold->ai_addr, hold->ai_addrlen);
> >> addr_set_port(&host->addr, 0);
> >> host->retries = 0;
> >
> > which I think is wrong, and wondering why:
> After the while loop doesn't hold point to the head of the list?
> If so, setting hold->ai_next = NULL; orphans the rest of the list, right?
> Or am I missing something...
>
> steved.
>

After the while loop, hold points to the original head of the list.
However the new head of this list was put in place by
*next = hold->ai_next;

as next == &host->ai, the above line is equivalent to

host->ai = host->ai->ai_next;

which clearly move the head pointer to the second entry.
hold->ai_next also points to this new head, so we have to clear it
(hold->ai = NULL) when we attach it to the end of the list
(*next = hold;, after the while loop).

NeilBrown