diff --git a/ChangeLog b/ChangeLog
index 03b19c0667234bc2bcdba7c4e5b207af608aa195..47a64321b2ce39d52d22448f0a9aadc6296865ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
-2010-04-09 Chris Allegretta <chrisa@asty.org>
+2010-04-14 Chris Allegretta <chrisa@asty.org>
 	* text.c (do_alt_speller): Skip invoking the alt speller if the file size 
 	  is 0 bytes.  Fixes Savannah bug 29393 reported by Mike Frysinger.
+	* files.c (wirte_file): Don't set current_stat when tmp == TRUE, check
+	  whether current_stat is set when trying to use it, and don't do the
+	  modification check if the filename changed, since we have no way
+	  of knowing about it in that case.  Fixes Savannah bug 29392, reported
+	  by Mike Frysinger.
 
 2010-04-13 Felipe Bugno <necron@bol.com.br>
 	* doc/syntax/cmake.nanorc: Added cmake syntax highlighting file.
diff --git a/src/files.c b/src/files.c
index bbb06977ab50a478ea02b79e467e6156a9f0047a..07915ce89d34df20371802f693d246ee4e0c12e6 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1501,11 +1501,11 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
 
 #ifndef NANO_TINY
     /* if we have not stat()d this file before (say, the user just
-     * specified it interactively), use the info we just got from
-     * stat()ing or else we will chase null pointers when we do
+     * specified it interactively), stat and save the value
+     * or else we will chase null pointers when we do
      * modtime checks, preserve file times, etc. during backup */
-    if (openfile->current_stat == NULL && realexists)
-	openfile->current_stat = &st;
+    if (openfile->current_stat == NULL && !tmp && realexists)
+	stat(realname, openfile->current_stat);
 
     /* We backup only if the backup toggle is set, the file isn't
      * temporary, and the file already exists.  Furthermore, if we
@@ -1513,8 +1513,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
      * only if the file has not been modified by someone else since nano
      * opened it. */
     if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append !=
-	OVERWRITE || openfile->mark_set) ||
-	openfile->current_stat->st_mtime == st.st_mtime)) {
+	OVERWRITE || openfile->mark_set) || (openfile->current_stat &&
+	openfile->current_stat->st_mtime == st.st_mtime))) {
 	int backup_fd;
 	FILE *backup_file;
 	char *backupname;
@@ -2141,8 +2141,9 @@ bool do_writeout(bool exiting)
 		    }
 		}
 #ifndef NANO_TINY
-
-		if (name_exists && openfile->current_stat && (openfile->current_stat->st_mtime < st.st_mtime ||
+		/* Complain if the file exists, the name hasn't changed, and the
+		    stat information we had before does not match what we have now */
+		else if (name_exists && openfile->current_stat && (openfile->current_stat->st_mtime < st.st_mtime ||
                     openfile->current_stat->st_dev != st.st_dev || openfile->current_stat->st_ino != st.st_ino)) {
 		    i = do_yesno_prompt(FALSE,
 			_("File was modified since you opened it, continue saving ? "));