summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2008-06-18 17:13:54 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2008-06-18 17:13:54 +0000
commit7cba576e0f687e33b63e4c1cd3b3094f775d296a (patch)
tree381c824e6dec18320c59b20fe253bf2779cc2ff2 /usr.bin/mg
parente00ab68c76420f89c0b894b5196323166a60c61d (diff)
Don't free the buffer name until after you call adjustname.
Fixes a segfault that occurs when you write a file to an alternate name. Introduced by yours truly in 20060406. how did it last this long?
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/file.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index ae4036a020e..cf4b744de35 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.66 2008/06/13 18:45:41 kjell Exp $ */
+/* $OpenBSD: file.c,v 1.67 2008/06/18 17:13:53 kjell Exp $ */
/* This file is in the public domain. */
@@ -514,10 +514,10 @@ filewrite(int f, int n)
(void)strlcpy(curbp->b_fname, adjfname, sizeof(curbp->b_fname));
if (getbufcwd(curbp->b_cwd, sizeof(curbp->b_cwd)) != TRUE)
(void)strlcpy(curbp->b_cwd, "/", sizeof(curbp->b_cwd));
- free(curbp->b_bname);
if (augbname(bn, basename(curbp->b_fname), sizeof(bn))
== FALSE)
return (FALSE);
+ free(curbp->b_bname);
if ((curbp->b_bname = strdup(bn)) == NULL)
return (FALSE);
curbp->b_flag &= ~(BFBAK | BFCHG);