diff --git a/src/sbbs3/ringbuf.c b/src/sbbs3/ringbuf.c
index fd9d7bea2eb7143c232fb64ade6bfb803246531f..8c6728b91e8493241f518f387c0284eba224e246 100644
--- a/src/sbbs3/ringbuf.c
+++ b/src/sbbs3/ringbuf.c
@@ -52,11 +52,13 @@
 	#ifndef VTOOLSD
 
 	/* FreeBSD uses <stdlib.h> instead of <malloc.h> */
-	#ifndef __FreeBSD__
-	#include <malloc.h>		/* malloc prototype */
+	#ifdef __FreeBSD__
+		#include <stdlib.h>
+	#else
+		#include <malloc.h>		/* malloc prototype */
 	#endif
-    #include <string.h>		/* memcpy prototype */
-    #endif
+	#include <string.h>			/* memcpy prototype */
+    #endif	/* !VTOOLSD */
 
 	#define os_malloc	malloc
 	#define rb_malloc	malloc
diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index 0d9af957af1389b46a1e24e2adc39a78b5fa0e5c..28c829a09978f368d05c538db0ac7037e8e087f5 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -20,7 +20,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <share.h>
-#include <malloc.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +30,10 @@
 	#include <mem.h>
 #endif
 
+#ifndef __FreeBSD__
+	#include <malloc.h>
+#endif
+
 #include "sbbs.h"			/* load_cfg() */
 #include "smbwrap.h"		/* lock/unlock() */
 #include "sbbswrap.h"		/* glob_t */
diff --git a/src/smblib/smbtxt.c b/src/smblib/smbtxt.c
index 49db571c11d98f64c3380b5e2e42e2de0946c6a7..76477e0097877eb5c6c54b07768be810922bb61e 100644
--- a/src/smblib/smbtxt.c
+++ b/src/smblib/smbtxt.c
@@ -37,7 +37,9 @@
 
 /* ANSI */
 
-#ifndef __FreeBSD__
+#ifdef __FreeBSD__
+	#include <stdlib.h>		/* malloc/realloc/free is defined here */
+#else
 	#include <malloc.h>
 #endif
 
@@ -46,7 +48,9 @@
 
 char HUGE16*  SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
 {
-	char	HUGE16* buf=NULL,HUGE16* lzhbuf,HUGE16* p;
+	char	HUGE16* buf=NULL;
+	char	HUGE16* lzhbuf;
+	char	HUGE16* p;
 	ushort	xlat;
 	int 	i,lzh;
 	long	l=0,lzhlen,length;
@@ -72,7 +76,7 @@ char HUGE16*  SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
 			length-=2;
 			if(length<1)
 				continue;
-			if((lzhbuf=LMALLOC(length))==NULL) {
+			if((lzhbuf=(char HUGE16*)LMALLOC(length))==NULL) {
 				sprintf(smb->last_error
 					,"malloc failure of %ld bytes for LZH buffer"
 					,length);
@@ -80,7 +84,7 @@ char HUGE16*  SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
 			}
 			smb_fread(lzhbuf,length,smb->sdt_fp);
 			lzhlen=*(long*)lzhbuf;
-			if((p=REALLOC(buf,l+lzhlen+3L))==NULL) {
+			if((p=(char HUGE16*)REALLOC(buf,l+lzhlen+3L))==NULL) {
 				sprintf(smb->last_error
 					,"realloc failure of %ld bytes for text buffer"
 					,l+lzhlen+3L);
@@ -93,7 +97,7 @@ char HUGE16*  SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
 			l+=lzhlen; 
 		}
 		else {
-			if((p=REALLOC(buf,l+length+3L))==NULL) {
+			if((p=(char HUGE16*)REALLOC(buf,l+length+3L))==NULL) {
 				sprintf(smb->last_error
 					,"realloc failure of %ld bytes for text buffer"
 					,l+length+3L);