diff options
author | 1998-08-16 21:22:18 +0000 | |
---|---|---|
committer | 1998-08-16 21:22:18 +0000 | |
commit | cc45442802cf61443cd93d8f0c1f98df847c8ec3 (patch) | |
tree | 310319e31bf6352732081709c4551cb8806882ea | |
parent | fix realloc memory leaks (diff) | |
download | wireguard-openbsd-cc45442802cf61443cd93d8f0c1f98df847c8ec3.tar.xz wireguard-openbsd-cc45442802cf61443cd93d8f0c1f98df847c8ec3.zip |
fix realloc use
-rw-r--r-- | usr.sbin/rwhod/rwhod.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c index 931557c3cb4..a028191897f 100644 --- a/usr.sbin/rwhod/rwhod.c +++ b/usr.sbin/rwhod/rwhod.c @@ -39,7 +39,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "@(#)rwhod.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: rwhod.c,v 1.11 1998/07/13 02:11:51 millert Exp $"; +static char rcsid[] = "$OpenBSD: rwhod.c,v 1.12 1998/08/16 21:22:18 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -286,6 +286,7 @@ onalrm(signo) struct stat stb; double avenrun[3]; time_t now; + struct utmp *nutmp; int cc; now = time(NULL); @@ -298,14 +299,17 @@ onalrm(signo) if (stb.st_size > utmpsize) { utmpsize = stb.st_size + 10 * sizeof(struct utmp); if (utmp) - utmp = (struct utmp *)realloc(utmp, utmpsize); + nutmp = (struct utmp *)realloc(utmp, utmpsize); else - utmp = (struct utmp *)malloc(utmpsize); - if (! utmp) { + nutmp = (struct utmp *)malloc(utmpsize); + if (!nutmp) { fprintf(stderr, "rwhod: malloc failed\n"); + if (utmp) + free(utmp); utmpsize = 0; goto done; } + utmp = nutmp; } (void) lseek(utmpf, (off_t)0, SEEK_SET); cc = read(utmpf, (char *)utmp, stb.st_size); |