diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-07 13:09:40 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-07 13:09:40 +0000 |
commit | d04e8e86fb999311c02f6cd80d2442cedf55b3f1 (patch) | |
tree | 4925113f64599172b8fd0cee07a751370f9eb721 /usr.bin | |
parent | b9680e2bb213866c22aaf7440309ed39647d36a6 (diff) |
Avoid excessive malloc/free for select in readdata()
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sup/src/scmio.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/usr.bin/sup/src/scmio.c b/usr.bin/sup/src/scmio.c index 42327b473a5..9524748de75 100644 --- a/usr.bin/sup/src/scmio.c +++ b/usr.bin/sup/src/scmio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scmio.c,v 1.8 2001/05/07 02:06:48 millert Exp $ */ +/* $OpenBSD: scmio.c,v 1.9 2001/05/07 13:09:39 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -445,14 +445,12 @@ readdata(count, data) /* read raw data from network */ int n, m, x; int tries; struct timeval timout; + static size_t rfdsize; static fd_set *readfds; static int bufcnt = 0; static char *bufptr; static char buffer[FILEXFER]; - if (readfds) - free(readfds); - if (count < 0) { if (bufptr + count < buffer) return (scmerr(-1, "No space in buffer %d", count)); @@ -476,6 +474,13 @@ readdata(count, data) /* read raw data from network */ data += bufcnt; count -= bufcnt; } + if (rfdsize < howmany(netfile+1, NFDBITS) * sizeof(fd_mask)) { + rfdsize = howmany(netfile+1, NFDBITS) * sizeof(fd_mask); + p = readfds ? realloc(readfds, rfdsize) : malloc(rfdsize); + if (p == NULL) + return (SCMERR); + readfds = (fd_set *) p; + } bufptr = buffer; bufcnt = 0; timout.tv_usec = 0; @@ -483,10 +488,6 @@ readdata(count, data) /* read raw data from network */ p = buffer; n = FILEXFER; m = count; - readfds = (fd_set *) calloc(howmany(netfile+1, NFDBITS), - sizeof(fd_mask)); - if (readfds == NULL) - return (SCMERR); while (m > 0) { tries = 0; for (;;) { |