diff --git a/src/nano.c b/src/nano.c
index 356a1de3aa17c3d45940ba834df8f2933e4307e5..93598607fb3813454a20457270e75bbfb3a140b3 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -605,7 +605,7 @@ void die(const char *msg, ...)
 
 #ifndef NANO_TINY
     /* If the current buffer has a lockfile, remove it. */
-    if (ISSET(LOCKING) && openfile->lock_filename)
+    if (openfile && ISSET(LOCKING) && openfile->lock_filename)
 	delete_lockfile(openfile->lock_filename);
 #endif