summaryrefslogtreecommitdiff
path: root/libexec/comsat
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-24 20:38:15 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-24 20:38:15 +0000
commite6f41ae5b7e0592cc4addc0aeebe15c9cc0d0889 (patch)
tree0fa95aefd1077a3f3d688a51a662208d378586de /libexec/comsat
parentec19aa60740f126a20db480421538626daf6e0f4 (diff)
realloc fixes; ho ok
Diffstat (limited to 'libexec/comsat')
-rw-r--r--libexec/comsat/comsat.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c
index 11b1c25b12c..47081aea1c7 100644
--- a/libexec/comsat/comsat.c
+++ b/libexec/comsat/comsat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: comsat.c,v 1.28 2003/06/19 22:35:34 deraadt Exp $ */
+/* $OpenBSD: comsat.c,v 1.29 2003/09/24 20:38:14 deraadt Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -37,7 +37,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)comsat.c 8.1 (Berkeley) 6/4/93";*/
-static char rcsid[] = "$OpenBSD: comsat.c,v 1.28 2003/06/19 22:35:34 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: comsat.c,v 1.29 2003/09/24 20:38:14 deraadt Exp $";
#endif /* not lint */
#include <sys/limits.h>
@@ -186,11 +186,18 @@ doreadutmp(void)
exit(1);
}
if (statbf.st_size > utmpsize) {
- utmpsize = statbf.st_size + 10 * sizeof(struct utmp);
- if ((utmp = realloc(utmp, utmpsize)) == NULL) {
+ u_int nutmpsize = statbf.st_size + 10 *
+ sizeof(struct utmp);
+ struct utmp *u;
+
+ if ((u = realloc(utmp, nutmpsize)) == NULL) {
+ if (utmp)
+ free(utmp);
syslog(LOG_ERR, "%s", strerror(errno));
exit(1);
}
+ u = utmp;
+ utmpsize = nutmpsize;
}
(void)lseek(uf, (off_t)0, SEEK_SET);
nutmp = read(uf, utmp, (int)statbf.st_size)/sizeof(struct utmp);