diff --git a/src/filesrch.c b/src/filesrch.c
index 9828c9f2551cad94c643430c1662b7f041d73497..483950ff50ca0e9b207cef28d3af9700ddbc585b 100644
--- a/src/filesrch.c
+++ b/src/filesrch.c
@@ -256,6 +256,28 @@ readdir (DIR * dirp)
   return (struct dirent *) 0;
 }
 
+/*
+ * rewinddir
+ *
+ * Makes the next readdir start from the beginning.
+ */
+int
+rewinddir (DIR * dirp)
+{
+  errno = 0;
+
+  /* Check for valid DIR struct. */
+  if (!dirp)
+    {
+      errno = EFAULT;
+      return -1;
+    }
+
+  dirp->dd_stat = 0;
+
+  return 0;
+}
+
 /*
  * closedir
  *
@@ -537,12 +559,11 @@ boolean preparefilemenu(boolean samemenu)
 		}
 	}
 
-	closedir(dirhandle); // I don't know how to go back to the start of the folder without just opening and closing... if there's a way, it doesn't appear to be easily manipulatable
-
 	if (!sizedirmenu)
 	{
 		if (tempname)
 			Z_Free(tempname);
+		closedir(dirhandle);
 		return false;
 	}
 
@@ -554,9 +575,12 @@ boolean preparefilemenu(boolean samemenu)
 	}
 
 	if (!(dirmenu = Z_Realloc(dirmenu, sizedirmenu*sizeof(char *), PU_STATIC, NULL)))
+	{
+		closedir(dirhandle); // just in case
 		I_Error("Ran out of memory whilst preparing add-ons menu");
+	}
 
-	dirhandle = opendir(menupath);
+	rewinddir(dirhandle);
 
 	while ((pos+folderpos) < sizedirmenu)
 	{
@@ -635,7 +659,7 @@ boolean preparefilemenu(boolean samemenu)
 		dirmenu[0] = Z_StrDup("\1\5UP...");
 
 	menupath[menupathindex[menudepthleft]] = 0;
-	sizedirmenu = (numfolders+pos); // crash prevention if things change between openings somehow
+	sizedirmenu = (numfolders+pos); // just in case things shrink between opening and rewind
 
 	if (tempname)
 	{