diff --git a/configure.ac b/configure.ac
index 656ee37168713d8a1690552a6d56797c7f4696cd..b689c6417f939fc0189bd12feb813e286577d7aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,7 @@ fi
 
 AC_CHECK_FUNCS([lrintf])
 AC_CHECK_FUNCS([lrint])
+AC_CHECK_FUNCS([__malloc_hook])
 
 AC_CHECK_SIZEOF(short)
 AC_CHECK_SIZEOF(int)
diff --git a/tests/test_opus_api.c b/tests/test_opus_api.c
index 2a451e453fe3c463e3ecb22a926af88850671e09..4246d16fda4ba0298ef922b8f68f8081ffced633 100644
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -61,7 +61,7 @@
 #define VG_CHECK(x,y)
 #endif
 
-#ifdef __GLIBC__
+#if defined(__GLIBC__) && defined(HAVE___MALLOC_HOOK)
 #define MALLOC_FAIL
 #include "os_support.h"
 #include <malloc.h>