From b692241cd435df7168f9c2147463eb0cc1660ecf Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 30 Aug 2016 14:08:16 +0000 Subject: [PATCH] Fix fd leak on error. OK jsg@ --- usr.sbin/cron/user.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/usr.sbin/cron/user.c b/usr.sbin/cron/user.c index 7e5d64a2040..0f19b0bdc2c 100644 --- a/usr.sbin/cron/user.c +++ b/usr.sbin/cron/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.18 2015/11/15 23:24:24 millert Exp $ */ +/* $OpenBSD: user.c,v 1.19 2016/08/30 14:08:16 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -54,7 +54,7 @@ load_user(int crontab_fd, struct passwd *pw, const char *name) user *u; entry *e; int status, save_errno; - char **envp, **tenvp; + char **envp = NULL, **tenvp; if (!(file = fdopen(crontab_fd, "r"))) { syslog(LOG_ERR, "(%s) FDOPEN (%m)", pw->pw_name); @@ -64,12 +64,13 @@ load_user(int crontab_fd, struct passwd *pw, const char *name) /* file is open. build user entry, then read the crontab file. */ if ((u = malloc(sizeof(user))) == NULL) - return (NULL); + goto done; if ((u->name = strdup(name)) == NULL) { save_errno = errno; free(u); + u = NULL; errno = save_errno; - return (NULL); + goto done; } SLIST_INIT(&u->crontab); @@ -77,10 +78,10 @@ load_user(int crontab_fd, struct passwd *pw, const char *name) */ if ((envp = env_init()) == NULL) { save_errno = errno; - free(u->name); - free(u); + free_user(u); + u = NULL; errno = save_errno; - return (NULL); + goto done; } /* load the crontab @@ -107,7 +108,8 @@ load_user(int crontab_fd, struct passwd *pw, const char *name) } done: - env_free(envp); + if (envp != NULL) + env_free(envp); fclose(file); return (u); } -- 2.20.1