summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnil Madhavapeddy <avsm@cvs.openbsd.org>2003-09-18 23:33:45 +0000
committerAnil Madhavapeddy <avsm@cvs.openbsd.org>2003-09-18 23:33:45 +0000
commit4acfe76abe7c1bb638c337a44f9e0c5ddb63c6fc (patch)
tree8d728f7b4b842ac78ad40b3e2e1dc150ad3b7ede
parent240ac230097f69997311fb7b2a4d806a8d9cfd8f (diff)
realloc spring cleaning, simplifies the code some
beck@ ok, deraadt@ ok an earlier version
-rw-r--r--libexec/spamd/spamd.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c
index 4385ed553ff..5d6fcc419bb 100644
--- a/libexec/spamd/spamd.c
+++ b/libexec/spamd/spamd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spamd.c,v 1.42 2003/09/04 01:20:33 tedu Exp $ */
+/* $OpenBSD: spamd.c,v 1.43 2003/09/18 23:33:44 avsm Exp $ */
/*
* Copyright (c) 2002 Theo de Raadt. All rights reserved.
@@ -137,13 +137,19 @@ grow_obuf(struct con *cp, int off)
if (!cp->obufalloc)
cp->obuf = NULL;
tmp = realloc(cp->obuf, cp->osize + 8192);
- if (tmp != NULL) {
+ if (tmp == NULL) {
+ if (cp->obuf)
+ free(cp->obuf);
+ cp->obuf = NULL;
+ cp->osize = 0;
+ cp->obufalloc = 0;
+ return (NULL);
+ } else {
cp->osize += 8192;
cp->obuf = tmp;
cp->obufalloc = 1;
return (cp->obuf + off);
- }
- return (NULL);
+ }
}
@@ -201,8 +207,13 @@ parse_configline(char *line)
char **tmp;
tmp = realloc(av, (ac + 2048) * sizeof(char *));
- if (tmp == NULL)
+ if (tmp == NULL) {
+ if (av)
+ free(av);
+ av = NULL;
+ ac = 0;
return (-1);
+ }
av = tmp;
ac += 2048;
}
@@ -332,7 +343,7 @@ append_error_string(struct con *cp, size_t off, char *fmt, int af, void *ia)
if (i >= len - 46) {
c = grow_obuf(cp, off);
if (c == NULL)
- goto no_mem;
+ return (-1);
len = cp->osize - (off + i);
}
@@ -389,13 +400,6 @@ append_error_string(struct con *cp, size_t off, char *fmt, int af, void *ia)
s++;
}
return (i);
-no_mem:
- /* Out of memory, free obuf and bail, caller must deal */
- if (cp->osize)
- free(cp->obuf);
- cp->obuf = NULL;
- cp->osize = 0;
- return (-1);
}
@@ -440,13 +444,8 @@ build_reply(struct con *cp)
if (cp->obuf[off - 1] != '\n') {
if (left < 1) {
c = grow_obuf(cp, off);
- if (c == NULL) {
- if (cp->osize)
- free(cp->obuf);
- cp->obuf = NULL;
- cp->osize = 0;
+ if (c == NULL)
goto bad;
- }
}
cp->obuf[off++] = '\n';
cp->obuf[off] = '\0';