-/* $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")
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);
/* 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);
*/
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
}
done:
- env_free(envp);
+ if (envp != NULL)
+ env_free(envp);
fclose(file);
return (u);
}