summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ripd/parse.y
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2009-03-31 21:03:48 +0000
committertobias <tobias@openbsd.org>2009-03-31 21:03:48 +0000
commit7fc93de09e3b12ad1a17e6c564bb4fa0981ae274 (patch)
treebab58cb5ff9dae32829aa14cca528a3f8e0476c5 /usr.sbin/ripd/parse.y
parentBackout previous change; it breaks more machines than it fixes. (diff)
downloadwireguard-openbsd-7fc93de09e3b12ad1a17e6c564bb4fa0981ae274.tar.xz
wireguard-openbsd-7fc93de09e3b12ad1a17e6c564bb4fa0981ae274.zip
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/ripd/parse.y')
-rw-r--r--usr.sbin/ripd/parse.y10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/ripd/parse.y b/usr.sbin/ripd/parse.y
index 5f7d1d748cc..b4427c9a437 100644
--- a/usr.sbin/ripd/parse.y
+++ b/usr.sbin/ripd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.23 2009/03/24 19:26:13 michele Exp $ */
+/* $OpenBSD: parse.y,v 1.24 2009/03/31 21:03:49 tobias Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -684,11 +684,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);