summaryrefslogtreecommitdiff
path: root/usr.bin/mg/fileio.c
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2003-05-06 10:45:08 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2003-05-06 10:45:08 +0000
commit3044561aeb3ecd9d4614f54561f3de8bcb4b8ad9 (patch)
tree1a19fa65ba2e7cb29cf36fd047b3bd115eb6dfe7 /usr.bin/mg/fileio.c
parent1519a81f79993ad792f0d02543a684976447324e (diff)
fix a small memleak on errors. noticed by pat latifi.
ok millert, fgsch
Diffstat (limited to 'usr.bin/mg/fileio.c')
-rw-r--r--usr.bin/mg/fileio.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index 493e2defa7f..5498b049bd4 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.34 2002/08/22 23:28:19 deraadt Exp $ */
+/* $OpenBSD: fileio.c,v 1.35 2003/05/06 10:45:07 vincent Exp $ */
/*
* POSIX fileio.c
@@ -168,15 +168,16 @@ fbackupfile(const char *fn)
char buf[BUFSIZ];
char *nname;
+ if (stat(fn, &sb) == -1) {
+ ewprintf("Can't stat %s : %s", fn, strerror(errno));
+ return (FALSE);
+ }
+
if (asprintf(&nname, "%s~", fn) == -1) {
ewprintf("Can't allocate temp file name : %s",
strerror(errno));
return (ABORT);
}
- if (stat(fn, &sb) == -1) {
- ewprintf("Can't stat %s : %s", fn, strerror(errno));
- return (FALSE);
- }
if ((from = open(fn, O_RDONLY)) == -1) {
free(nname);