diff --git a/src/crontab.c b/src/crontab.c index f61fd46..29402bb 100644 --- a/src/crontab.c +++ b/src/crontab.c @@ -500,8 +500,8 @@ static int backup_crontab(const char *crontab_path) { const char *env_value; char backup_dir[MAX_FNAME], backup_path[MAX_FNAME]; int ch = '\0'; - FILE *crontab_file; - FILE *backup_file; + FILE *crontab_file = NULL; + FILE *backup_file = NULL; struct stat sb; int retval = 0; mode_t old_umask; @@ -594,18 +594,19 @@ static int backup_crontab(const char *crontab_path) { } if (retval != 0) - return retval; + goto cleanup; if (EOF != ch) while (EOF != (ch = get_char(crontab_file))) putc(ch, backup_file); + printf("Backup of %s's previous crontab saved to %s\n", User, backup_path); + +cleanup: (void) fclose(crontab_file); (void) fclose(backup_file); - printf("Backup of %s's previous crontab saved to %s\n", User, backup_path); - - return 0; + return retval; } static void check_error(const char *msg) {