diff --git a/libavcodec/aacps.c b/libavcodec/aacps.c
index 22df160fe7..df77752be1 100644
--- a/libavcodec/aacps.c
+++ b/libavcodec/aacps.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include "libavutil/common.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/mem_internal.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "aacps.h"
diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c
index 1d2a8d472d..0ab33101ce 100644
--- a/libavcodec/aacsbr.c
+++ b/libavcodec/aacsbr.c
@@ -39,6 +39,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/libm.h"
 #include "libavutil/avassert.h"
+#include "libavutil/mem_internal.h"
 
 #include <stdint.h>
 #include <float.h>
diff --git a/libavcodec/aarch64/vp9dsp_init_16bpp_aarch64_template.c b/libavcodec/aarch64/vp9dsp_init_16bpp_aarch64_template.c
index 8dcfdeaaf7..d2a4e90b3a 100644
--- a/libavcodec/aarch64/vp9dsp_init_16bpp_aarch64_template.c
+++ b/libavcodec/aarch64/vp9dsp_init_16bpp_aarch64_template.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/aarch64/cpu.h"
 #include "vp9dsp_init.h"
 
diff --git a/libavcodec/aarch64/vp9dsp_init_aarch64.c b/libavcodec/aarch64/vp9dsp_init_aarch64.c
index 4c699759fe..4d1fee62de 100644
--- a/libavcodec/aarch64/vp9dsp_init_aarch64.c
+++ b/libavcodec/aarch64/vp9dsp_init_aarch64.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/aarch64/cpu.h"
 #include "libavcodec/vp9dsp.h"
 #include "vp9dsp_init.h"
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 37dc0fb2ef..0afe94a909 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -34,6 +34,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "internal.h"
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index b85fe51ef5..b74e38aea0 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -30,6 +30,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 
 #include "audiodsp.h"
 #include "internal.h"
diff --git a/libavcodec/arm/vp9dsp_init_16bpp_arm_template.c b/libavcodec/arm/vp9dsp_init_16bpp_arm_template.c
index 1b0007859d..b0907094c1 100644
--- a/libavcodec/arm/vp9dsp_init_16bpp_arm_template.c
+++ b/libavcodec/arm/vp9dsp_init_16bpp_arm_template.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/arm/cpu.h"
 #include "vp9dsp_init.h"
 
diff --git a/libavcodec/arm/vp9dsp_init_arm.c b/libavcodec/arm/vp9dsp_init_arm.c
index cb7f48d5ca..b3911f7e49 100644
--- a/libavcodec/arm/vp9dsp_init_arm.c
+++ b/libavcodec/arm/vp9dsp_init_arm.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/arm/cpu.h"
 #include "libavcodec/vp9dsp.h"
 #include "vp9dsp_init.h"
diff --git a/libavcodec/atrac3plusdsp.c b/libavcodec/atrac3plusdsp.c
index 7af1fa2141..e32c5c8170 100644
--- a/libavcodec/atrac3plusdsp.c
+++ b/libavcodec/atrac3plusdsp.c
@@ -29,6 +29,8 @@
 
 #include "libavutil/float_dsp.h"
 #include "libavutil/libm.h"
+#include "libavutil/mem_internal.h"
+
 #include "avcodec.h"
 #include "sinewin.h"
 #include "fft.h"
diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index ec164d0165..5efd24e9c3 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -23,6 +23,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 747fdafd3e..2f8060df89 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -21,6 +21,7 @@
 #define BITSTREAM_READER_LE
 
 #include "libavutil/channel_layout.h"
+#include "libavutil/mem_internal.h"
 
 #include "dcadec.h"
 #include "dcadata.h"
diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
index fade1a6c02..faf244c8ad 100644
--- a/libavcodec/dcadsp.c
+++ b/libavcodec/dcadsp.c
@@ -19,6 +19,7 @@
  */
 
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #include "dcadsp.h"
 #include "dcamath.h"
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 34b3e94165..a40d2e0ca0 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -28,6 +28,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
 #include "libavutil/ffmath.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dca.h"
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 91eeb47e33..0144797d1b 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -25,6 +25,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 
 #include "avcodec.h"
diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 429612ec08..2b2f0a1640 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -21,6 +21,7 @@
 #include "libavutil/float_dsp.h"
 #include "libavutil/thread.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #include "internal.h"
 #include "get_bits.h"
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index c526091eb4..a0647e58b4 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -38,6 +38,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/pixdesc.h"
 
 #include "avcodec.h"
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 21a8b841f6..0dc290642e 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -30,6 +30,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 
diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index 0924f32613..558ec6c02d 100644
--- a/libavcodec/h264_loopfilter.c
+++ b/libavcodec/h264_loopfilter.c
@@ -27,6 +27,7 @@
 
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 #include "internal.h"
 #include "avcodec.h"
 #include "h264dec.h"
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index c26d8b0149..444b7f5428 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -38,7 +38,9 @@
 #include "libavutil/ffmath.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "bswapdsp.h"
 #include "get_bits.h"
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index ced7fa52ee..c9007b2fd6 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -34,6 +34,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/mem_internal.h"
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "h263.h"
diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c
index f8da1e1266..1d1d04fd80 100644
--- a/libavcodec/lpc.c
+++ b/libavcodec/lpc.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/common.h"
 #include "libavutil/lls.h"
+#include "libavutil/mem_internal.h"
 
 #define LPC_USE_DOUBLE
 #include "lpc.h"
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index ae248c52f8..ba72468240 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "avcodec.h"
 #include "copy_block.h"
 #include "simple_idct.h"
diff --git a/libavcodec/mips/aacsbr_mips.c b/libavcodec/mips/aacsbr_mips.c
index 5ef5e68371..33fd9b229e 100644
--- a/libavcodec/mips/aacsbr_mips.c
+++ b/libavcodec/mips/aacsbr_mips.c
@@ -53,6 +53,7 @@
 
 #include "libavcodec/aac.h"
 #include "libavcodec/aacsbr.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/mips/asmdefs.h"
 
 #define ENVELOPE_ADJUSTMENT_OFFSET 2
diff --git a/libavcodec/mips/vc1dsp_mmi.c b/libavcodec/mips/vc1dsp_mmi.c
index 98378683b8..79f19a9b39 100644
--- a/libavcodec/mips/vc1dsp_mmi.c
+++ b/libavcodec/mips/vc1dsp_mmi.c
@@ -25,6 +25,7 @@
 #include "constants.h"
 #include "vc1dsp_mips.h"
 #include "hpeldsp_mips.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/mips/mmiutils.h"
 
 #define VC1_INV_TRANCS_8_TYPE1(o1, o2, r1, r2, r3, r4, c0)                  \
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index 720d67623f..af12a6fd8e 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -28,7 +28,9 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/internal.h"
 #include "libavutil/lfg.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "get_bits.h"
 #include "internal.h"
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 243d3ca632..25d9004199 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -36,6 +36,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/intmath.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 5624c10629..58cdecf83b 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -25,6 +25,8 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
+
 #include "avcodec.h"
 #include "h261.h"
 #include "mpegutils.h"
diff --git a/libavcodec/ppc/mpegaudiodsp_altivec.c b/libavcodec/ppc/mpegaudiodsp_altivec.c
index efa9fd5fed..6794ed0928 100644
--- a/libavcodec/ppc/mpegaudiodsp_altivec.c
+++ b/libavcodec/ppc/mpegaudiodsp_altivec.c
@@ -23,6 +23,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/ppc/cpu.h"
 #include "libavutil/ppc/util_altivec.h"
 #include "libavcodec/mpegaudiodsp.h"
diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c
index 5fd2796115..136f341c08 100644
--- a/libavcodec/proresdec2.c
+++ b/libavcodec/proresdec2.c
@@ -29,6 +29,8 @@
 #define LONG_BITSTREAM_READER
 
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
+
 #include "avcodec.h"
 #include "get_bits.h"
 #include "idctdsp.h"
diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index 8bc13fd576..c34e55f873 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -27,6 +27,7 @@
  * Known FOURCCs: 'ap4h' (444), 'apch' (HQ), 'apcn' (422), 'apcs' (LT), 'acpo' (Proxy)
  */
 
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dct.h"
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 8df17891b1..3fe69a2f3d 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -22,6 +22,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 13f9b609e2..e29dbb9779 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -27,6 +27,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
 
 #include "avcodec.h"
diff --git a/libavcodec/speedhq.c b/libavcodec/speedhq.c
index 748e8617f6..419900025a 100644
--- a/libavcodec/speedhq.c
+++ b/libavcodec/speedhq.c
@@ -27,6 +27,7 @@
 #define BITSTREAM_READER_LE
 
 #include "libavutil/attributes.h"
+#include "libavutil/mem_internal.h"
 
 #include "avcodec.h"
 #include "get_bits.h"
diff --git a/libavcodec/tests/dct.c b/libavcodec/tests/dct.c
index 2ca8039c01..eab39e9468 100644
--- a/libavcodec/tests/dct.c
+++ b/libavcodec/tests/dct.c
@@ -38,6 +38,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/lfg.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/time.h"
 
 #include "libavcodec/dct.h"
diff --git a/libavcodec/tests/x86/dct.c b/libavcodec/tests/x86/dct.c
index afb03b194b..f5c238efc7 100644
--- a/libavcodec/tests/x86/dct.c
+++ b/libavcodec/tests/x86/dct.c
@@ -18,6 +18,8 @@
 
 #include "config.h"
 
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/x86/fdct.h"
 #include "libavcodec/x86/xvididct.h"
 #include "libavcodec/x86/simple_idct.h"
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index d5d133540a..9440969728 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -25,6 +25,7 @@
  */
 
 #include "libavutil/imgutils.h"
+#include "libavutil/mem_internal.h"
 
 #include "avcodec.h"
 #include "hwconfig.h"
diff --git a/libavcodec/vp9recon.c b/libavcodec/vp9recon.c
index 9a4e7c7a03..e38cf99ec5 100644
--- a/libavcodec/vp9recon.c
+++ b/libavcodec/vp9recon.c
@@ -22,6 +22,7 @@
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/mem_internal.h"
 
 #include "avcodec.h"
 #include "internal.h"
diff --git a/libavcodec/x86/cavsdsp.c b/libavcodec/x86/cavsdsp.c
index becb3a4808..f974f93fc0 100644
--- a/libavcodec/x86/cavsdsp.c
+++ b/libavcodec/x86/cavsdsp.c
@@ -25,6 +25,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
 #include "libavutil/cpu.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/cavsdsp.h"
diff --git a/libavcodec/x86/h264_qpel.c b/libavcodec/x86/h264_qpel.c
index 0d3dbbadb0..a2d8a64976 100644
--- a/libavcodec/x86/h264_qpel.c
+++ b/libavcodec/x86/h264_qpel.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/h264dec.h"
diff --git a/libavcodec/x86/hevcdsp_init.c b/libavcodec/x86/hevcdsp_init.c
index 17cd2332aa..8a3fa2744b 100644
--- a/libavcodec/x86/hevcdsp_init.c
+++ b/libavcodec/x86/hevcdsp_init.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "libavutil/cpu.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/get_bits.h" /* required for hevcdsp.h GetBitContext */
diff --git a/libavcodec/x86/mpegaudiodsp.c b/libavcodec/x86/mpegaudiodsp.c
index d646c6dbcb..50692f29ce 100644
--- a/libavcodec/x86/mpegaudiodsp.c
+++ b/libavcodec/x86/mpegaudiodsp.c
@@ -22,6 +22,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/mpegaudiodsp.h"
diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c
index 1201be514b..b32b1b0350 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -23,6 +23,7 @@
 #include <stdint.h>
 
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavcodec/mpegutils.h"
 #include "libavcodec/mpegvideo.h"
diff --git a/libavcodec/x86/rv40dsp_init.c b/libavcodec/x86/rv40dsp_init.c
index b57a3fc31a..79a617ffbe 100644
--- a/libavcodec/x86/rv40dsp_init.c
+++ b/libavcodec/x86/rv40dsp_init.c
@@ -29,6 +29,7 @@
 #include "libavcodec/rv34dsp.h"
 #include "libavutil/attributes.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/cpu.h"
 #include "hpeldsp.h"
 
diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c
index 45c8a68f29..6541dda429 100644
--- a/libavcodec/x86/vc1dsp_mmx.c
+++ b/libavcodec/x86/vc1dsp_mmx.c
@@ -26,6 +26,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/asm.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/vc1dsp.h"
diff --git a/libavcodec/x86/vp8dsp_init.c b/libavcodec/x86/vp8dsp_init.c
index 397b2518cb..dffa7a2418 100644
--- a/libavcodec/x86/vp8dsp_init.c
+++ b/libavcodec/x86/vp8dsp_init.c
@@ -23,6 +23,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/vp8dsp.h"
 
diff --git a/libavcodec/x86/vp9dsp_init.h b/libavcodec/x86/vp9dsp_init.h
index e410cab3a1..ebe7ca8ad0 100644
--- a/libavcodec/x86/vp9dsp_init.h
+++ b/libavcodec/x86/vp9dsp_init.h
@@ -23,6 +23,8 @@
 #ifndef AVCODEC_X86_VP9DSP_INIT_H
 #define AVCODEC_X86_VP9DSP_INIT_H
 
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/vp9dsp.h"
 
 // hack to force-expand BPC
diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 4551ce2b83..bcb99dbfc3 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -36,6 +36,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/float_dsp.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/tx.h"
 #include "avfilter.h"
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 12f824d97a..80c5d06326 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -92,10 +92,6 @@
     type av_##name##_get_##field(const str *s) { return s->field; } \
     void av_##name##_set_##field(str *s, type v) { s->field = v; }
 
-// Some broken preprocessors need a second expansion
-// to be forced to tokenize __VA_ARGS__
-#define E1(x) x
-
 /* Check if the hard coded offset of a struct member still matches reality.
  * Induce a compilation failure if not.
  */
@@ -103,39 +99,6 @@
         int x_##o[offsetof(s, m) == o? 1: -1];         \
     }
 
-#define LOCAL_ALIGNED_A(a, t, v, s, o, ...)             \
-    uint8_t la_##v[sizeof(t s o) + (a)];                \
-    t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
-
-#define LOCAL_ALIGNED_D(a, t, v, s, o, ...)             \
-    DECLARE_ALIGNED(a, t, la_##v) s o;                  \
-    t (*v) o = la_##v
-
-#define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
-
-#if HAVE_LOCAL_ALIGNED
-#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
-#else
-#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
-#endif
-
-#if HAVE_LOCAL_ALIGNED
-#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
-#else
-#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
-#endif
-
-#if HAVE_LOCAL_ALIGNED
-#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
-#else
-#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
-#endif
-
-#if HAVE_LOCAL_ALIGNED
-#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
-#else
-#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
-#endif
 
 #define FF_ALLOC_TYPED_ARRAY(p, nelem)  (p = av_malloc_array(nelem, sizeof(*p)))
 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_mallocz_array(nelem, sizeof(*p)))
diff --git a/libavutil/mem_internal.h b/libavutil/mem_internal.h
index 6fdbcb016e..14f45c657f 100644
--- a/libavutil/mem_internal.h
+++ b/libavutil/mem_internal.h
@@ -21,9 +21,51 @@
 #ifndef AVUTIL_MEM_INTERNAL_H
 #define AVUTIL_MEM_INTERNAL_H
 
+#include "config.h"
+
+#include <stdint.h>
+
 #include "avassert.h"
 #include "mem.h"
 
+// Some broken preprocessors need a second expansion
+// to be forced to tokenize __VA_ARGS__
+#define E1(x) x
+
+#define LOCAL_ALIGNED_A(a, t, v, s, o, ...)             \
+    uint8_t la_##v[sizeof(t s o) + (a)];                \
+    t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
+
+#define LOCAL_ALIGNED_D(a, t, v, s, o, ...)             \
+    DECLARE_ALIGNED(a, t, la_##v) s o;                  \
+    t (*v) o = la_##v
+
+#define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
+#endif
+
+#if HAVE_LOCAL_ALIGNED
+#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
+#else
+#   define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
+#endif
+
 static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
 {
     void *val;
diff --git a/libavutil/mips/mmiutils.h b/libavutil/mips/mmiutils.h
index 8f692e86c5..6a82caa908 100644
--- a/libavutil/mips/mmiutils.h
+++ b/libavutil/mips/mmiutils.h
@@ -25,6 +25,8 @@
 #define AVUTIL_MIPS_MMIUTILS_H
 
 #include "config.h"
+
+#include "libavutil/mem_internal.h"
 #include "libavutil/mips/asmdefs.h"
 
 #if HAVE_LOONGSON2
diff --git a/libavutil/tests/lls.c b/libavutil/tests/lls.c
index 965b0f458d..4c14c0c4b4 100644
--- a/libavutil/tests/lls.c
+++ b/libavutil/tests/lls.c
@@ -22,6 +22,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/lfg.h"
 #include "libavutil/lls.h"
+#include "libavutil/mem_internal.h"
 
 int main(void)
 {
diff --git a/libswscale/ppc/swscale_ppc_template.c b/libswscale/ppc/swscale_ppc_template.c
index aff2dd79f9..0ffa92725b 100644
--- a/libswscale/ppc/swscale_ppc_template.c
+++ b/libswscale/ppc/swscale_ppc_template.c
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mem_internal.h"
+
 static void FUNC(yuv2planeX_8_16)(const int16_t *filter, int filterSize,
                                   const int16_t **src, uint8_t *dest,
                                   const uint8_t *dither, int offset, int x)
diff --git a/libswscale/ppc/swscale_vsx.c b/libswscale/ppc/swscale_vsx.c
index af8b0e1fa3..8152ce7f10 100644
--- a/libswscale/ppc/swscale_vsx.c
+++ b/libswscale/ppc/swscale_vsx.c
@@ -28,6 +28,7 @@
 #include "libswscale/swscale_internal.h"
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
+#include "libavutil/mem_internal.h"
 #include "yuv2rgb_altivec.h"
 #include "libavutil/ppc/util_altivec.h"
 
diff --git a/tests/checkasm/aacpsdsp.c b/tests/checkasm/aacpsdsp.c
index 2ceef4341f..359b1e9a00 100644
--- a/tests/checkasm/aacpsdsp.c
+++ b/tests/checkasm/aacpsdsp.c
@@ -18,6 +18,7 @@
 
 #include "libavcodec/aacpsdsp.h"
 #include "libavutil/intfloat.h"
+#include "libavutil/mem_internal.h"
 
 #include "checkasm.h"
 
diff --git a/tests/checkasm/af_afir.c b/tests/checkasm/af_afir.c
index 8d1f815469..b8a845db82 100644
--- a/tests/checkasm/af_afir.c
+++ b/tests/checkasm/af_afir.c
@@ -23,6 +23,7 @@
 
 #include "libavfilter/af_afir.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 #include "checkasm.h"
 
 #define LEN 256
diff --git a/tests/checkasm/alacdsp.c b/tests/checkasm/alacdsp.c
index cbf03f82e8..b822c725cf 100644
--- a/tests/checkasm/alacdsp.c
+++ b/tests/checkasm/alacdsp.c
@@ -24,6 +24,7 @@
 #include "libavcodec/mathops.h"
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 256
 #define MAX_CHANNELS 2
diff --git a/tests/checkasm/audiodsp.c b/tests/checkasm/audiodsp.c
index 7c4e16e40d..d3a5604299 100644
--- a/tests/checkasm/audiodsp.c
+++ b/tests/checkasm/audiodsp.c
@@ -25,6 +25,7 @@
 
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #include "checkasm.h"
 
diff --git a/tests/checkasm/blockdsp.c b/tests/checkasm/blockdsp.c
index c753506b3c..9e6ce9d7d1 100644
--- a/tests/checkasm/blockdsp.c
+++ b/tests/checkasm/blockdsp.c
@@ -27,6 +27,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define randomize_buffers(size)             \
     do {                                    \
diff --git a/tests/checkasm/bswapdsp.c b/tests/checkasm/bswapdsp.c
index 5f7555037d..d789e90de3 100644
--- a/tests/checkasm/bswapdsp.c
+++ b/tests/checkasm/bswapdsp.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 512
 
diff --git a/tests/checkasm/exrdsp.c b/tests/checkasm/exrdsp.c
index 754a079f83..2a5febb9d3 100644
--- a/tests/checkasm/exrdsp.c
+++ b/tests/checkasm/exrdsp.c
@@ -24,6 +24,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/exrdsp.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 5120
 #define PADDED_BUF_SIZE BUF_SIZE+AV_INPUT_BUFFER_PADDING_SIZE*2
diff --git a/tests/checkasm/fixed_dsp.c b/tests/checkasm/fixed_dsp.c
index fa11f2e23f..4e610a148e 100644
--- a/tests/checkasm/fixed_dsp.c
+++ b/tests/checkasm/fixed_dsp.c
@@ -23,6 +23,7 @@
 #include "libavutil/fixed_dsp.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 256
 
diff --git a/tests/checkasm/flacdsp.c b/tests/checkasm/flacdsp.c
index dccb54d672..6cd8ac50ef 100644
--- a/tests/checkasm/flacdsp.c
+++ b/tests/checkasm/flacdsp.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 256
 #define MAX_CHANNELS 8
diff --git a/tests/checkasm/float_dsp.c b/tests/checkasm/float_dsp.c
index a1616a61a8..1437d8ee97 100644
--- a/tests/checkasm/float_dsp.c
+++ b/tests/checkasm/float_dsp.c
@@ -23,6 +23,8 @@
 
 #include "libavutil/float_dsp.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
+
 #include "checkasm.h"
 
 #define LEN 256
diff --git a/tests/checkasm/fmtconvert.c b/tests/checkasm/fmtconvert.c
index 50ad3ca2ea..aef74479f6 100644
--- a/tests/checkasm/fmtconvert.c
+++ b/tests/checkasm/fmtconvert.c
@@ -24,6 +24,8 @@
 
 #include "libavutil/internal.h"
 #include "libavutil/common.h"
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/fmtconvert.h"
 
 #include "checkasm.h"
diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c
index 6975205743..7392452957 100644
--- a/tests/checkasm/h264dsp.c
+++ b/tests/checkasm/h264dsp.c
@@ -26,6 +26,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
 static const uint32_t pixel_mask_lf[3] = { 0xff0fff0f, 0x01ff000f, 0x03ff000f };
diff --git a/tests/checkasm/h264pred.c b/tests/checkasm/h264pred.c
index 59dcb2f427..a3077f6946 100644
--- a/tests/checkasm/h264pred.c
+++ b/tests/checkasm/h264pred.c
@@ -25,6 +25,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 static const int codec_ids[4] = { AV_CODEC_ID_H264, AV_CODEC_ID_VP8, AV_CODEC_ID_RV40, AV_CODEC_ID_SVQ3 };
 
diff --git a/tests/checkasm/h264qpel.c b/tests/checkasm/h264qpel.c
index ba069f1259..e47d659929 100644
--- a/tests/checkasm/h264qpel.c
+++ b/tests/checkasm/h264qpel.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
 
diff --git a/tests/checkasm/hevc_add_res.c b/tests/checkasm/hevc_add_res.c
index 0a3bcbb706..0c896adaca 100644
--- a/tests/checkasm/hevc_add_res.c
+++ b/tests/checkasm/hevc_add_res.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #include "libavcodec/hevcdsp.h"
 
diff --git a/tests/checkasm/hevc_idct.c b/tests/checkasm/hevc_idct.c
index c20111c2df..338b8a23e4 100644
--- a/tests/checkasm/hevc_idct.c
+++ b/tests/checkasm/hevc_idct.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #include "libavcodec/hevcdsp.h"
 
diff --git a/tests/checkasm/hevc_sao.c b/tests/checkasm/hevc_sao.c
index 8d0cf80774..6b750758e2 100644
--- a/tests/checkasm/hevc_sao.c
+++ b/tests/checkasm/hevc_sao.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #include "libavcodec/avcodec.h"
 
diff --git a/tests/checkasm/jpeg2000dsp.c b/tests/checkasm/jpeg2000dsp.c
index bce534dbaf..c9158ab3de 100644
--- a/tests/checkasm/jpeg2000dsp.c
+++ b/tests/checkasm/jpeg2000dsp.c
@@ -23,6 +23,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 512
 
diff --git a/tests/checkasm/llviddspenc.c b/tests/checkasm/llviddspenc.c
index 31eafd5526..132f6d2771 100644
--- a/tests/checkasm/llviddspenc.c
+++ b/tests/checkasm/llviddspenc.c
@@ -23,6 +23,7 @@
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #include "libavcodec/lossless_videoencdsp.h"
 
diff --git a/tests/checkasm/opusdsp.c b/tests/checkasm/opusdsp.c
index 828ecf9ce2..34ee5a4edc 100644
--- a/tests/checkasm/opusdsp.c
+++ b/tests/checkasm/opusdsp.c
@@ -16,6 +16,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/opusdsp.h"
 
 #include "checkasm.h"
diff --git a/tests/checkasm/pixblockdsp.c b/tests/checkasm/pixblockdsp.c
index 79ab156d45..9a7865aa5f 100644
--- a/tests/checkasm/pixblockdsp.c
+++ b/tests/checkasm/pixblockdsp.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_UNITS 8
 #define BUF_SIZE (BUF_UNITS * 128 + 8 * BUF_UNITS)
diff --git a/tests/checkasm/sbrdsp.c b/tests/checkasm/sbrdsp.c
index 516b9f0ec6..2fb14d5bf8 100644
--- a/tests/checkasm/sbrdsp.c
+++ b/tests/checkasm/sbrdsp.c
@@ -16,6 +16,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/sbrdsp.h"
 #include <float.h>
 
diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c
index e5aad20c6d..c29b75d09b 100644
--- a/tests/checkasm/sw_rgb.c
+++ b/tests/checkasm/sw_rgb.c
@@ -22,6 +22,7 @@
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #include "libswscale/rgb2rgb.h"
 
diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c
index 9efa2b4def..8741b3943c 100644
--- a/tests/checkasm/sw_scale.c
+++ b/tests/checkasm/sw_scale.c
@@ -22,6 +22,7 @@
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
 
 #include "libswscale/swscale.h"
 #include "libswscale/swscale_internal.h"
diff --git a/tests/checkasm/synth_filter.c b/tests/checkasm/synth_filter.c
index 87e32ebc0e..9a0d746c96 100644
--- a/tests/checkasm/synth_filter.c
+++ b/tests/checkasm/synth_filter.c
@@ -25,6 +25,8 @@
 
 #include "libavutil/internal.h"
 #include "libavutil/intfloat.h"
+#include "libavutil/mem_internal.h"
+
 #include "libavcodec/dcadata.h"
 #include "libavcodec/synth_filter.h"
 
diff --git a/tests/checkasm/utvideodsp.c b/tests/checkasm/utvideodsp.c
index 080b4287d7..bdede6107b 100644
--- a/tests/checkasm/utvideodsp.c
+++ b/tests/checkasm/utvideodsp.c
@@ -24,6 +24,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/utvideodsp.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define WIDTH 240
 #define HEIGHT 120
diff --git a/tests/checkasm/v210enc.c b/tests/checkasm/v210enc.c
index ed3677659d..c3d5cc5145 100644
--- a/tests/checkasm/v210enc.c
+++ b/tests/checkasm/v210enc.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define BUF_SIZE 512
 
diff --git a/tests/checkasm/vf_colorspace.c b/tests/checkasm/vf_colorspace.c
index 10b7b83924..31efa671f9 100644
--- a/tests/checkasm/vf_colorspace.c
+++ b/tests/checkasm/vf_colorspace.c
@@ -24,6 +24,7 @@
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define W 64
 #define H 64
diff --git a/tests/checkasm/vf_eq.c b/tests/checkasm/vf_eq.c
index 48dccddf77..1315b08f0e 100644
--- a/tests/checkasm/vf_eq.c
+++ b/tests/checkasm/vf_eq.c
@@ -21,6 +21,7 @@
 #include "libavfilter/avfilter.h"
 #include "libavfilter/vf_eq.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define WIDTH 256
 #define HEIGHT 256
diff --git a/tests/checkasm/vf_hflip.c b/tests/checkasm/vf_hflip.c
index 2d6fdeca7b..a3b6e613d5 100644
--- a/tests/checkasm/vf_hflip.c
+++ b/tests/checkasm/vf_hflip.c
@@ -20,6 +20,7 @@
 #include "checkasm.h"
 #include "libavfilter/hflip.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define WIDTH 256
 #define WIDTH_PADDED 256 + 32
diff --git a/tests/checkasm/vf_threshold.c b/tests/checkasm/vf_threshold.c
index 5a2fc0e4ee..2c5cc807ee 100644
--- a/tests/checkasm/vf_threshold.c
+++ b/tests/checkasm/vf_threshold.c
@@ -20,6 +20,7 @@
 #include "checkasm.h"
 #include "libavfilter/threshold.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define WIDTH 256
 #define WIDTH_PADDED 256 + 32
diff --git a/tests/checkasm/videodsp.c b/tests/checkasm/videodsp.c
index 0a4424a28c..eb2845a7d9 100644
--- a/tests/checkasm/videodsp.c
+++ b/tests/checkasm/videodsp.c
@@ -23,6 +23,7 @@
 #include "libavcodec/videodsp.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #define randomize_buffers(w, h)                         \
     do {                                                \
diff --git a/tests/checkasm/vp8dsp.c b/tests/checkasm/vp8dsp.c
index d93f73087f..c3af54fbfd 100644
--- a/tests/checkasm/vp8dsp.c
+++ b/tests/checkasm/vp8dsp.c
@@ -25,6 +25,7 @@
 
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 
 #include "checkasm.h"
 
diff --git a/tests/checkasm/vp9dsp.c b/tests/checkasm/vp9dsp.c
index a91577b94e..99c023899f 100644
--- a/tests/checkasm/vp9dsp.c
+++ b/tests/checkasm/vp9dsp.c
@@ -27,6 +27,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/mem_internal.h"
 
 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
