summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2009-03-31 21:03:50 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2009-03-31 21:03:50 +0000
commitd1f46a5bae81083eb4d20a65b677c8159dadb2a2 (patch)
treeed98e68c11b6221bd5077066cf218fd07f6cce05 /usr.sbin/smtpd
parent9b03618dbfb1bc94a0cd3d53ea0e26dc12a627c7 (diff)
Fixed memory leaks which would occur if the second of two memory
allocations fails. looks right deraadt, krw ok henning
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/parse.y18
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 90d3ce7b226..5021a42cf8f 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.29 2009/03/19 00:40:34 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.30 2009/03/31 21:03:49 tobias Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1228,11 +1228,15 @@ pushfile(const char *name, int secret)
{
struct file *nfile;
- if ((nfile = calloc(1, sizeof(struct file))) == NULL ||
- (nfile->name = strdup(name)) == NULL) {
+ if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
log_warn("malloc");
return (NULL);
}
+ if ((nfile->name = strdup(name)) == NULL) {
+ log_warn("malloc");
+ free(nfile);
+ return (NULL);
+ }
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
log_warn("%s", nfile->name);
free(nfile->name);
@@ -1273,9 +1277,13 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts)
conf = x_conf;
bzero(conf, sizeof(*conf));
- if ((conf->sc_maps = calloc(1, sizeof(*conf->sc_maps))) == NULL ||
- (conf->sc_rules = calloc(1, sizeof(*conf->sc_rules))) == NULL) {
+ if ((conf->sc_maps = calloc(1, sizeof(*conf->sc_maps))) == NULL) {
+ log_warn("cannot allocate memory");
+ return 0;
+ }
+ if ((conf->sc_rules = calloc(1, sizeof(*conf->sc_rules))) == NULL) {
log_warn("cannot allocate memory");
+ free(conf->sc_maps);
return 0;
}