summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-10-30 16:53:14 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-10-30 16:53:14 +0000
commitf6c16da93ee22d0e0e6fc7df6358728fab7778a0 (patch)
treeca86779d8cb9c0de6ed183efa603374ee9153eea
parenta2a032a8ddb3ece8bcd215751ad195d5dcd28f88 (diff)
correct realloc() misuse
-rw-r--r--lib/libc/time/ialloc.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/libc/time/ialloc.c b/lib/libc/time/ialloc.c
index 39bb4db7dce..648b75be7c1 100644
--- a/lib/libc/time/ialloc.c
+++ b/lib/libc/time/ialloc.c
@@ -1,6 +1,6 @@
#if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID)
static char elsieid[] = "@(#)ialloc.c 8.29";
-static char rcsid[] = "$OpenBSD: ialloc.c,v 1.5 1998/08/14 21:39:43 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ialloc.c,v 1.6 2001/10/30 16:53:13 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*LINTLIBRARY*/
@@ -31,9 +31,14 @@ irealloc(pointer, size)
void * const pointer;
const int size;
{
+ void *p;
+
if (pointer == NULL)
return imalloc(size);
- return realloc((void *) pointer, (size_t) nonzero(size));
+ p = realloc((void *) pointer, (size_t) nonzero(size));
+ if (p == NULL && pointer)
+ free(pointer);
+ return p;
}
char *
@@ -49,7 +54,8 @@ const char * const new;
oldsize = 0;
else if (newsize == 0)
return old;
- else oldsize = strlen(old);
+ else
+ oldsize = strlen(old);
if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL)
(void) strcpy(result + oldsize, new);