diff --git a/src/filesrch.c b/src/filesrch.c
index b90123d4b6335779ba575c033859fec246ce4f57..ff389fa3db190ea3eba9f4a5f3900cbed0f3d834 100644
--- a/src/filesrch.c
+++ b/src/filesrch.c
@@ -293,7 +293,7 @@ size_t menudepthleft = 20;
 
 char **dirmenu;
 size_t sizedirmenu;
-size_t dir_on;
+size_t dir_on[20];
 
 #if defined (_XBOX) && defined (_MSC_VER)
 filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum,
@@ -483,16 +483,14 @@ boolean preparefilemenu(void)
 	DIR *dirhandle;
 	struct dirent *dent;
 	struct stat fsstat;
-	size_t pos, folderpos = 0, numfolders = 0;
+	size_t pos = 0, folderpos = 0, numfolders = 0;
 
-	for (pos = 0; pos < sizedirmenu; pos++)
+	for (; sizedirmenu > 0; sizedirmenu--)
 	{
-		Z_Free(dirmenu[pos]);
-		dirmenu[pos] = NULL;
+		Z_Free(dirmenu[sizedirmenu-1]);
+		dirmenu[sizedirmenu-1] = NULL;
 	}
 
-	sizedirmenu = dir_on = pos = 0;
-
 	dirhandle = opendir(menupath);
 
 	if (dirhandle == NULL)
diff --git a/src/filesrch.h b/src/filesrch.h
index c6d16159736d81eaa9fa684c2f572f3bab7093dd..0ce7ff94c772cd01a21931b17fbadae32a4db4ae 100644
--- a/src/filesrch.h
+++ b/src/filesrch.h
@@ -31,7 +31,7 @@ extern size_t menudepthleft;
 
 extern char **dirmenu;
 extern size_t sizedirmenu;
-extern size_t dir_on;
+extern size_t dir_on[20];
 
 boolean preparefilemenu(void);
 
diff --git a/src/m_menu.c b/src/m_menu.c
index a3ee63ecbecbbdbf716db208501195c3d029986a..d491712ae487fb49c1164170b58fee85f732b1db 100644
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -4459,6 +4459,8 @@ static void M_Addons(INT32 choice)
 		M_StartMessage(M_GetText("No files/folders found.\n\n(Press a key)\n"),NULL,MM_NOTHING);
 		return;
 	}
+	else
+		dir_on[menudepthleft] = 0;
 
 	MISC_AddonsDef.prevMenu = currentMenu;
 	M_SetupNextMenu(&MISC_AddonsDef);
@@ -4476,7 +4478,7 @@ static void M_DrawAddons(void)
 	V_DrawString(x, y, 0, menupath);
 	y += 2*SMALLLINEHEIGHT;
 
-	for (i = dir_on; i < sizedirmenu; i++)
+	for (i = dir_on[menudepthleft]; i < sizedirmenu; i++)
 	{
 		if (y > BASEVIDHEIGHT) break;
 		V_DrawString(x, y, 0, dirmenu[i]+2);
@@ -4491,21 +4493,21 @@ static void M_HandleAddons(INT32 choice)
 	switch (choice)
 	{
 		case KEY_DOWNARROW:
-			if (dir_on < sizedirmenu-1)
-				dir_on++;
+			if (dir_on[menudepthleft] < sizedirmenu-1)
+				dir_on[menudepthleft]++;
 			S_StartSound(NULL, sfx_menu1);
 			break;
 		case KEY_UPARROW:
-			if (dir_on)
-				dir_on--;
+			if (dir_on[menudepthleft])
+				dir_on[menudepthleft]--;
 			S_StartSound(NULL, sfx_menu1);
 			break;
 		case KEY_ENTER:
-			if (dirmenu[dir_on][0] == 0) // folder
+			if (dirmenu[dir_on[menudepthleft]][0] == 0) // folder
 			{
 				S_StartSound(NULL, sfx_strpst);
-				strcpy(&menupath[menupathindex[menudepthleft--]],dirmenu[dir_on]+2);
-				menupathindex[menudepthleft] = strlen(menupath);
+				strcpy(&menupath[menupathindex[menudepthleft]],dirmenu[dir_on[menudepthleft]]+2);
+				menupathindex[--menudepthleft] = strlen(menupath);
 				menupath[menupathindex[menudepthleft]] = 0;
 
 				if (!preparefilemenu())
@@ -4519,11 +4521,13 @@ static void M_HandleAddons(INT32 choice)
 						return;
 					}
 				}
+				else
+					dir_on[menudepthleft] = 0;
 			}
-			else if (dirmenu[dir_on][0] >= 3) // wad/soc/lua
+			else if (dirmenu[dir_on[menudepthleft]][0] >= 3) // wad/soc/lua
 			{
 				S_StartSound(NULL, sfx_strpst);
-				COM_BufAddText(va("addfile %s%s", menupath, dirmenu[dir_on]+2));
+				COM_BufAddText(va("addfile %s%s", menupath, dirmenu[dir_on[menudepthleft]]+2));
 			}
 			else
 				S_StartSound(NULL, sfx_lose);
@@ -4540,6 +4544,7 @@ static void M_HandleAddons(INT32 choice)
 				}
 				break;
 			}
+			// intentional fallthrough
 		case KEY_ESCAPE:
 			exitmenu = true;
 			break;
@@ -4549,6 +4554,15 @@ static void M_HandleAddons(INT32 choice)
 	}
 	if (exitmenu)
 	{
+		for (; sizedirmenu > 0; sizedirmenu--)
+		{
+			Z_Free(dirmenu[sizedirmenu-1]);
+			dirmenu[sizedirmenu-1] = NULL;
+		}
+
+		Z_Free(dirmenu);
+		dirmenu = NULL;
+
 		if (currentMenu->prevMenu)
 			M_SetupNextMenu(currentMenu->prevMenu);
 		else