diff --git a/lib/memdebug.h b/lib/memdebug.h
index 2ee523327cb9297fd8b84f408e7783d4c2194804..03f154a1ef5851afeeffa6a751e519c174367a85 100644
--- a/lib/memdebug.h
+++ b/lib/memdebug.h
@@ -2,6 +2,9 @@
 
 #include <sys/socket.h>
 #include <stdio.h>
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
 
 /* memory functions */
 void *curl_domalloc(size_t size, int line, char *source);