select: how to find out the bad fd

The following code is used to detect a bad fd following an error return
from select:
Heres the code below, it is a longwinded way of find the bad descriptor.
We tested using this method and it seems the the bad file descriptor is
not clear and every call to select thereafter gives the same error.

if (select(fdmax+1, &read_fds, NULL, NULL, &tv) == -1) {
fprintf(stderr,“Error(%d) : select.\n”,errno);
for (i=(sock+1);i<=fdmax;i++) {
if(FD_ISSET(i, &master)) {
FD_ZERO(&check_fds);
FD_SET(i, &check_fds);
if (select(i+1, &check_fds, NULL, NULL, 0) == -1) {
fprintf(stderr,“Error(%d), found bad descriptor(%d),
clearing it (FDMAX=%d).\n”,errno,i,fdmax);
FD_CLR(i, &master);
}
}
}
}

It appears this method is not working as every call to select keeps on
return bad fd.
Any one have a better way of determining which fd is bad?

Thanks in advance