diff options
-rw-r--r-- | lib/libc/net/res_send.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index 798d0f6..9061ec6 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -56,7 +56,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; static char orig_rcsid[] = "From: Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_send.c,v 1.16 1997/06/27 08:22:03 peter Exp $"; +static char rcsid[] = "$Id: res_send.c,v 1.17 1997/06/27 13:00:51 peter Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -469,7 +469,8 @@ read_len: * Use datagrams. */ struct timeval timeout; - fd_set *dsmaskp; + fd_set dsmask, *dsmaskp; + int dsmasklen; struct sockaddr_in from; int fromlen; @@ -575,16 +576,22 @@ read_len: timeout.tv_sec = 1; timeout.tv_usec = 0; wait: - dsmaskp = (fd_set *)calloc(howmany(s+1, NFDBITS), - sizeof(fd_mask)); - if (dsmaskp == NULL) { - res_close(); - goto next_ns; - } + dsmasklen = howmany(s+1, NFDBITS) * sizeof(fd_mask); + if (dsmasklen > sizeof(fd_set)) { + dsmaskp = (fd_set *)malloc(dsmasklen); + if (dsmaskp == NULL) { + res_close(); + goto next_ns; + } + } else + dsmaskp = &dsmask; + /* only zero what we need */ + bzero((char *)dsmaskp, dsmasklen); FD_SET(s, dsmaskp); n = select(s+1, dsmaskp, (fd_set *)NULL, (fd_set *)NULL, &timeout); - free(dsmaskp); + if (dsmaskp != &dsmask) + free(dsmaskp); if (n < 0) { if (errno == EINTR) goto wait; |