diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index 92769641c5a0192bd63b65712b3840c8d4efa1f0..c7f39e459f75e34f1883900af42df68e012cf4bd 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -852,7 +852,7 @@ void sbbs_t::removeline(char *str, char *str2, char num, char skip)
 {
 	char*	buf;
     size_t  slen;
-    int     i,file;
+    int		i,file;
 	long	l=0,flen;
     FILE    *stream;
 
@@ -861,6 +861,11 @@ void sbbs_t::removeline(char *str, char *str2, char num, char skip)
 		return; 
 	}
 	flen=(long)filelength(file);
+	if(flen < 0) {
+		close(file);
+		errormsg(WHERE, ERR_CHK, str, flen);
+		return;
+	}
 	slen=strlen(str2);
 	if((buf=(char *)malloc(flen))==NULL) {
 		close(file);