diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-04 14:27:01 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-04 14:27:01 +0000 |
commit | f95bb7126416e0c68f3d0de3c8801a0d014f19e8 (patch) | |
tree | 8f0b45d204ec6b1a067aef9f89cae547edadda96 /lib/libc/stdlib | |
parent | 602950e0c9a390e1aa8fbbc87ad6adb00420307d (diff) |
Fix the leak for real (that's what I get for hacking when i can't sleep).
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r-- | lib/libc/stdlib/random.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index 2b97c5a54a2..5ce7c90ee9c 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: random.c,v 1.8 2000/04/04 13:38:24 millert Exp $"; +static char *rcsid = "$OpenBSD: random.c,v 1.9 2000/04/04 14:27:00 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -245,18 +245,20 @@ srandomdev() else len = rand_deg * sizeof(state[0]); - if ((fd = open("/dev/arandom", O_RDONLY, 0)) == -1 || - read(fd, (void *) state, len) != (ssize_t) len) { + if ((fd = open("/dev/arandom", O_RDONLY, 0)) != -1 && + read(fd, (void *) state, len) == (ssize_t) len) { + close(fd); + } else { struct timeval tv; u_int junk; /* XXX - this could be better */ gettimeofday(&tv, NULL); srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk); + if (fd != -1) + close(fd); return; } - if (fd != -1) - close(fd); if (rand_type != TYPE_0) { fptr = &state[rand_sep]; |