h-enumerate-r-safety-20051128

FIXES 23336

needs further testing, configure a low number of callbacks and hit the server.
This commit is contained in:
Chaskiel M Grundman 2005-11-29 03:40:58 +00:00 committed by Derrick Brashear
parent bb7b7cef79
commit 390fd697a0

View File

@ -895,18 +895,21 @@ h_Enumerate(int (*proc) (), char *param)
void void
h_Enumerate_r(int (*proc) (), struct host *enumstart, char *param) h_Enumerate_r(int (*proc) (), struct host *enumstart, char *param)
{ {
register struct host *host; register struct host *host, *next;
register int held; register int held, nheld;
if (hostCount == 0) { if (hostCount == 0) {
return; return;
} }
for (host = enumstart; host; host = host->next) { if (!(held = h_Held_r(host)))
if (!(held = h_Held_r(host))) h_Hold_r(host);
h_Hold_r(host); for (host = enumstart; host; host = next, held = nheld) {
held = (*proc) (host, held, param); held = (*proc) (host, held, param);
next = host->next;
if (next && !(nheld = h_Held_r(next)))
h_Hold_r(next);
if (!held) if (!held)
h_Release_r(host); /* this might free up the host */ h_Release_r(host); /* this might free up the host */
} }
} /*h_Enumerate_r */ } /*h_Enumerate_r */