From 6eaf622ca872513a384b705cdd35c8d1360dd06a Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 26 Sep 2003 07:15:42 +0000 Subject: realloc tuning; pvalchev ok --- usr.sbin/rwhod/rwhod.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c index a5ec8ec4d2d..aab647fbe28 100644 --- a/usr.sbin/rwhod/rwhod.c +++ b/usr.sbin/rwhod/rwhod.c @@ -35,7 +35,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.28 2003/06/08 17:05:36 mickey Exp $"; +static char rcsid[] = "$OpenBSD: rwhod.c,v 1.29 2003/09/26 07:15:41 deraadt Exp $"; #endif /* not lint */ #include @@ -355,19 +355,16 @@ timer(void) if ((stb.st_mtime != utmptime) || (stb.st_size > utmpsize)) { utmptime = stb.st_mtime; if (stb.st_size > utmpsize) { - utmpsize = stb.st_size + 10 * sizeof(struct utmp); - if (utmp) - nutmp = (struct utmp *)realloc(utmp, utmpsize); - else - nutmp = (struct utmp *)malloc(utmpsize); + int nutmpsize = stb.st_size + 10 * sizeof(struct utmp); + nutmp = (struct utmp *)realloc(utmp, nutmpsize); if (!nutmp) { warnx("malloc failed"); - if (utmp) - free(utmp); + free(utmp); utmpsize = 0; return; } utmp = nutmp; + utmpsize = nutmpsize; } (void) lseek(utmpf, (off_t)0, SEEK_SET); cc = read(utmpf, (char *)utmp, stb.st_size); -- cgit v1.2.3