diff --git a/src/sbbs3/bat_xfer.cpp b/src/sbbs3/bat_xfer.cpp
index 30a793f8036e9b85be6063c5f2b4bb9c53713faa..21315ea7d901811975b1e3541e49581374c10432 100644
--- a/src/sbbs3/bat_xfer.cpp
+++ b/src/sbbs3/bat_xfer.cpp
@@ -642,7 +642,8 @@ void sbbs_t::batch_upload()
 			uploadfile(&f); 
 		}
 	}
-	closedir(dir);
+	if(dir!=NULL)
+		closedir(dir);
 }
 
 /****************************************************************************/
diff --git a/src/sbbs3/pack_qwk.cpp b/src/sbbs3/pack_qwk.cpp
index 5a0738f2517df726353ce9d2269b5ae93d877a2a..43a7df758ed2fd3ce5010297a3a2fce38beb9f73 100644
--- a/src/sbbs3/pack_qwk.cpp
+++ b/src/sbbs3/pack_qwk.cpp
@@ -494,7 +494,8 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
 			if(!mv(str,tmp2,1))
 				netfiles++;
 		}
-		closedir(dir);
+		if(dir!=NULL)
+			closedir(dir);
 		if(netfiles)
 			CRLF; }
 
@@ -616,7 +617,8 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
 			if(!isdir(tmp))
 				remove(tmp); 
 		}
-		closedir(dir);
+		if(dir!=NULL)
+			closedir(dir);
 	}
 
 	return(true);
diff --git a/src/sbbs3/tmp_xfer.cpp b/src/sbbs3/tmp_xfer.cpp
index b523faacff2e079947f521fe6c4f2dc7707b32eb..a6bafa78559c741d672e6fc877a53a91eeb8e682 100644
--- a/src/sbbs3/tmp_xfer.cpp
+++ b/src/sbbs3/tmp_xfer.cpp
@@ -311,7 +311,8 @@ void sbbs_t::extract(uint dirnum)
         		if(!isdir(str))
 					remove(str);
 			}
-			closedir(dir);
+			if(dir!=NULL)
+				closedir(dir);
 			CRLF; 
 		} 
 	}
diff --git a/src/sbbs3/un_rep.cpp b/src/sbbs3/un_rep.cpp
index 7f1667f22c50415da99db5b09b5bc5098b394854..95b2b9498560a336215895c46c4c2dd7ccea1541 100644
--- a/src/sbbs3/un_rep.cpp
+++ b/src/sbbs3/un_rep.cpp
@@ -425,7 +425,8 @@ bool sbbs_t::unpack_rep(char* repfile)
 			sprintf(str,text[ReceivedFileViaQWK],dirent->d_name,useron.alias);
 			putsmsg(&cfg,1,str);
 		} 
-		closedir(dir);
+		if(dir!=NULL)
+			closedir(dir);
 		sprintf(str,"%sqnet-rep.now",cfg.data_dir);
 		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))!=-1)
 			close(file);
diff --git a/src/sbbs3/upload.cpp b/src/sbbs3/upload.cpp
index 030c4262b4c0515ee3d5c5b6db4b225fa7f18e04..c900270260fee3c28de8aa869495653b60768e5c 100644
--- a/src/sbbs3/upload.cpp
+++ b/src/sbbs3/upload.cpp
@@ -579,7 +579,8 @@ bool sbbs_t::bulkupload(uint dirnum)
 			uploadfile(&f); 
 		}
 	}
-	closedir(dir);
+	if(dir!=NULL)
+		closedir(dir);
 	if(sys_status&SS_ABORT)
 		return(true);
 	return(false);