summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd/parse.y
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/relayd/parse.y
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/relayd/parse.y')
-rw-r--r--usr.sbin/relayd/parse.y21
1 files changed, 18 insertions, 3 deletions
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index 41f5d653bae..8746e066c6d 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.127 2008/12/05 16:53:07 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.128 2009/03/31 21:03:49 tobias Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -1807,11 +1807,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);
@@ -1857,6 +1861,17 @@ parse_config(const char *filename, int opts)
(conf->sc_relays = calloc(1, sizeof(*conf->sc_relays))) == NULL ||
(conf->sc_protos = calloc(1, sizeof(*conf->sc_protos))) == NULL ||
(conf->sc_rdrs = calloc(1, sizeof(*conf->sc_rdrs))) == NULL) {
+ if (conf != NULL) {
+ if (conf->sc_tables != NULL)
+ free(conf->sc_tables);
+ if (conf->sc_relays != NULL)
+ free(conf->sc_relays);
+ if (conf->sc_protos != NULL)
+ free(conf->sc_protos);
+ if (conf->sc_rdrs != NULL)
+ free(conf->sc_rdrs);
+ free(conf);
+ }
log_warn("cannot allocate memory");
return (NULL);
}