summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1998-08-15 20:14:08 +0000
committerderaadt <deraadt@openbsd.org>1998-08-15 20:14:08 +0000
commitf652cbcbae649cd6283f68decf96b84ea82efeaf (patch)
tree03ba2a8bc4433b0dd52cdadb0e558062b5a6ef94
parentsimplify a few things wrt realloc (diff)
downloadwireguard-openbsd-f652cbcbae649cd6283f68decf96b84ea82efeaf.tar.xz
wireguard-openbsd-f652cbcbae649cd6283f68decf96b84ea82efeaf.zip
fix realloc
-rw-r--r--bin/rcp/util.c11
-rw-r--r--sbin/ccdconfig/ccdconfig.c6
2 files changed, 12 insertions, 5 deletions
diff --git a/bin/rcp/util.c b/bin/rcp/util.c
index 9380ed08c45..7d268a5e78c 100644
--- a/bin/rcp/util.c
+++ b/bin/rcp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.5 1997/09/01 18:30:24 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.6 1998/08/15 20:14:08 deraadt Exp $ */
/* $NetBSD: util.c,v 1.2 1995/03/21 08:19:08 cgd Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)util.c 8.2 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: util.c,v 1.5 1997/09/01 18:30:24 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.6 1998/08/15 20:14:08 deraadt Exp $";
#endif
#endif /* not lint */
@@ -143,6 +143,7 @@ allocbuf(bp, fd, blksize)
{
struct stat stb;
size_t size;
+ char *p;
if (fstat(fd, &stb) < 0) {
run_err("fstat: %s", strerror(errno));
@@ -153,11 +154,15 @@ allocbuf(bp, fd, blksize)
size = blksize;
if (bp->cnt >= size)
return (bp);
- if ((bp->buf = realloc(bp->buf, size)) == NULL) {
+ if ((p = realloc(bp->buf, size)) == NULL) {
+ if (bp->buf)
+ free(bp->buf);
+ bp->buf = NULL;
bp->cnt = 0;
run_err("%s", strerror(errno));
return (0);
}
+ bp->buf = p;
bp->cnt = size;
return (bp);
}
diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c
index 6986d8089a4..3e842304cfb 100644
--- a/sbin/ccdconfig/ccdconfig.c
+++ b/sbin/ccdconfig/ccdconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ccdconfig.c,v 1.11 1998/07/08 22:24:54 deraadt Exp $ */
+/* $OpenBSD: ccdconfig.c,v 1.12 1998/08/15 20:16:34 deraadt Exp $ */
/* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */
/*-
@@ -328,6 +328,7 @@ do_all(action)
char *cp, **argv;
int argc, rval = 0;
gid_t egid;
+ char **nargv;
egid = getegid();
setegid(getgid());
@@ -351,11 +352,12 @@ do_all(action)
for (cp = line; (cp = strtok(cp, " \t")) != NULL; cp = NULL) {
if (*cp == '#')
break;
- if ((argv = realloc(argv,
+ if ((nargv = realloc(argv,
sizeof(char *) * ++argc)) == NULL) {
warnx("no memory to configure ccds");
return (1);
}
+ argv = nargv;
argv[argc - 1] = cp;
/*
* If our action is to unconfigure all, then pass