From 313c1811bf5faa0d20cd8fc1f153383c0becc744 Mon Sep 17 00:00:00 2001 From: christos Date: Tue, 25 Apr 2006 18:02:02 +0000 Subject: [PATCH] Coverity CID 1774, 1773: Don't leak open file descriptors or leave temp file turds on error. --- usr.sbin/cron/crontab.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index 92d2415d88d6..70218209756c 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $NetBSD: crontab.c,v 1.26 2005/03/16 02:53:55 xtraeme Exp $ */ +/* $NetBSD: crontab.c,v 1.27 2006/04/25 18:02:02 christos Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ #if 0 static char rcsid[] = "Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp"; #else -__RCSID("$NetBSD: crontab.c,v 1.26 2005/03/16 02:53:55 xtraeme Exp $"); +__RCSID("$NetBSD: crontab.c,v 1.27 2006/04/25 18:02:02 christos Exp $"); #endif #endif @@ -562,12 +562,14 @@ replace_cmd(void) { if (fstat(fileno(NewCrontab), &statbuf)) { fprintf(stderr, "%s: error stat'ing crontab input: %s\n", ProgramName, strerror(errno)); + fclose(tmp); unlink(tn); return(-2); } if (statbuf.st_size > maxtabsize) { fprintf(stderr, "%s: %ld bytes is larger than the maximum size of %ld bytes\n", ProgramName, (long) statbuf.st_size, (long) maxtabsize); + fclose(tmp); unlink(tn); return(-1); } @@ -578,7 +580,7 @@ replace_cmd(void) { fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n"); fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now)); fprintf(tmp, "# (Cron version -- %s)\n", - "$NetBSD: crontab.c,v 1.26 2005/03/16 02:53:55 xtraeme Exp $"); + "$NetBSD: crontab.c,v 1.27 2006/04/25 18:02:02 christos Exp $"); /* copy the crontab to the tmp */