summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-24 20:39:19 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-24 20:39:19 +0000
commit3ee08ce607314cf704bf3875b67bc414b72a0464 (patch)
treea4bb968918958eb6dcdf9f53d87d5aa366f9669a /bin
parente6f41ae5b7e0592cc4addc0aeebe15c9cc0d0889 (diff)
realloc fixes; ok ho matthieu
Diffstat (limited to 'bin')
-rw-r--r--bin/ps/fmt.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c
index c9a8677b5ef..8de727a22eb 100644
--- a/bin/ps/fmt.c
+++ b/bin/ps/fmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt.c,v 1.4 2003/07/02 21:19:33 deraadt Exp $ */
+/* $OpenBSD: fmt.c,v 1.5 2003/09/24 20:39:18 deraadt Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -49,7 +49,7 @@
void
fmt_puts(char *s, int *leftp)
{
- static char *v = 0, *nv;
+ static char *v = NULL, *nv;
static int maxlen = 0;
int len;
@@ -57,13 +57,21 @@ fmt_puts(char *s, int *leftp)
return;
len = strlen(s) * 4 + 1;
if (len > maxlen) {
- if (maxlen == 0)
- maxlen = getpagesize();
- while (len > maxlen)
- maxlen *= 2;
- nv = realloc(v, maxlen);
- if (nv == 0)
+ int newmaxlen = maxlen;
+
+ if (newmaxlen == 0)
+ newmaxlen = getpagesize();
+ while (len > newmaxlen)
+ newmaxlen *= 2;
+ nv = realloc(v, newmaxlen);
+ if (nv == 0) {
+ if (v)
+ free(v);
+ v = NULL;
+ maxlen = 0;
return;
+ }
+ maxlen = newmaxlen;
v = nv;
}
strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);