summaryrefslogtreecommitdiffstats
path: root/usr.bin/truncate
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2006-09-18 16:39:23 +0000
committermaxim <maxim@FreeBSD.org>2006-09-18 16:39:23 +0000
commit3839b5384ddf1f9b95604f79429c842af6ee2a54 (patch)
tree38fe3faea468e5808c8a58c068043508e492cc03 /usr.bin/truncate
parent0477285943e7d95d567d6fc569a02ca0a87c8d9a (diff)
downloadFreeBSD-src-3839b5384ddf1f9b95604f79429c842af6ee2a54.zip
FreeBSD-src-3839b5384ddf1f9b95604f79429c842af6ee2a54.tar.gz
o Don't leak fd on error.
o parselength() returns 0 or -1 so int is enough for its return type. Submitted by: Ighighi Ighighi, sheldonh MFC after: 3 weeks
Diffstat (limited to 'usr.bin/truncate')
-rw-r--r--usr.bin/truncate/truncate.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/truncate/truncate.c b/usr.bin/truncate/truncate.c
index 469dbcb..98f7289 100644
--- a/usr.bin/truncate/truncate.c
+++ b/usr.bin/truncate/truncate.c
@@ -40,7 +40,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <unistd.h>
-static off_t parselength(char *, off_t *);
+static int parselength(char *, off_t *);
static void usage(void);
static int no_create;
@@ -108,6 +108,8 @@ main(int argc, char **argv)
omode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
while ((fname = *argv++) != NULL) {
+ if (fd != -1)
+ close(fd);
if ((fd = open(fname, oflags, omode)) == -1) {
if (errno != ENOENT) {
warn("%s", fname);
@@ -138,9 +140,9 @@ main(int argc, char **argv)
error++;
continue;
}
-
- close(fd);
}
+ if (fd != -1)
+ close(fd);
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
@@ -149,7 +151,7 @@ main(int argc, char **argv)
* Return the numeric value of a string given in the form [+-][0-9]+[GMKT]
* or -1 on format error or overflow.
*/
-static off_t
+static int
parselength(char *ls, off_t *sz)
{
off_t length, oflow;
OpenPOWER on IntegriCloud