diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 5636fdef2d..e523a6ea96 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -129,7 +129,7 @@ static VLC block_type_vlc[2][4];
 
 
 typedef struct CFrameBuffer {
-    unsigned int allocated_size;
+    size_t allocated_size;
     unsigned int size;
     int id;
     uint8_t *data;
@@ -895,8 +895,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
         if (data_size > UINT_MAX -  cfrm->size - AV_INPUT_BUFFER_PADDING_SIZE)
             return AVERROR_INVALIDDATA;
 
-        cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size,
-                                     cfrm->size + data_size + AV_INPUT_BUFFER_PADDING_SIZE);
+        cfrm->data = av_realloc_reuse(cfrm->data, &cfrm->allocated_size,
+                                      cfrm->size + data_size + AV_INPUT_BUFFER_PADDING_SIZE);
         // explicit check needed as memcpy below might not catch a NULL
         if (!cfrm->data) {
             av_log(f->avctx, AV_LOG_ERROR, "realloc failure\n");
diff --git a/libavcodec/audio_frame_queue.c b/libavcodec/audio_frame_queue.c
index 08b4b368c7..bd92fe23c0 100644
--- a/libavcodec/audio_frame_queue.c
+++ b/libavcodec/audio_frame_queue.c
@@ -43,7 +43,8 @@ void ff_af_queue_close(AudioFrameQueue *afq)
 
 int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
 {
-    AudioFrame *new = av_fast_realloc(afq->frames, &afq->frame_alloc, sizeof(*afq->frames)*(afq->frame_count+1));
+    AudioFrame *new = av_realloc_reuse(afq->frames, &afq->frame_alloc,
+                                       sizeof(*afq->frames)*(afq->frame_count+1));
     if(!new)
         return AVERROR(ENOMEM);
     afq->frames = new;
diff --git a/libavcodec/audio_frame_queue.h b/libavcodec/audio_frame_queue.h
index d8076eae54..8aa82ba5cf 100644
--- a/libavcodec/audio_frame_queue.h
+++ b/libavcodec/audio_frame_queue.h
@@ -35,7 +35,7 @@ typedef struct AudioFrameQueue {
     int remaining_samples;
     AudioFrame *frames;
     unsigned frame_count;
-    unsigned frame_alloc;
+    size_t frame_alloc;
 } AudioFrameQueue;
 
 /**
diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..baab46016b 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -70,7 +70,7 @@ int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *lo
 
             if (new_size >= INT_MAX / sizeof(*tmp))
                 return AVERROR(ENOMEM);
-            tmp = av_fast_realloc(pkt->obus, &pkt->obus_allocated_size, new_size * sizeof(*tmp));
+            tmp = av_realloc_reuse(pkt->obus, &pkt->obus_allocated_size, new_size * sizeof(*tmp));
             if (!tmp)
                 return AVERROR(ENOMEM);
 
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index f4a5d2830e..20ce94105d 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -63,7 +63,7 @@ typedef struct AV1Packet {
     AV1OBU *obus;
     int nb_obus;
     int obus_allocated;
-    unsigned obus_allocated_size;
+    size_t obus_allocated_size;
 } AV1Packet;
 
 /**
diff --git a/libavcodec/dirac_parser.c b/libavcodec/dirac_parser.c
index 912f594243..1de08e43db 100644
--- a/libavcodec/dirac_parser.c
+++ b/libavcodec/dirac_parser.c
@@ -46,7 +46,7 @@ typedef struct DiracParseContext {
     int sync_offset;
     int header_bytes_needed;
     int overread_index;
-    int buffer_size;
+    size_t buffer_size;
     int index;
     uint8_t *buffer;
     int dirac_unit_size;
@@ -156,8 +156,8 @@ static int dirac_combine_frame(AVCodecParserContext *s, AVCodecContext *avctx,
     if (next == -1) {
         /* Found a possible frame start but not a frame end */
         void *new_buffer =
-            av_fast_realloc(pc->buffer, &pc->buffer_size,
-                            pc->index + (*buf_size - pc->sync_offset));
+            av_realloc_reuse(pc->buffer, &pc->buffer_size,
+                             pc->index + (*buf_size - pc->sync_offset));
         if (!new_buffer)
             return AVERROR(ENOMEM);
         pc->buffer = new_buffer;
@@ -168,8 +168,8 @@ static int dirac_combine_frame(AVCodecParserContext *s, AVCodecContext *avctx,
     } else {
         /* Found a possible frame start and a  possible frame end */
         DiracParseUnit pu1, pu;
-        void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size,
-                                           pc->index + next);
+        void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size,
+                                            pc->index + next);
         if (!new_buffer)
             return AVERROR(ENOMEM);
         pc->buffer = new_buffer;
diff --git a/libavcodec/dxva2_av1.c b/libavcodec/dxva2_av1.c
index 228f72ba18..6520f82c9f 100644
--- a/libavcodec/dxva2_av1.c
+++ b/libavcodec/dxva2_av1.c
@@ -33,7 +33,7 @@
 struct AV1DXVAContext {
     FFDXVASharedContext shared;
 
-    unsigned int bitstream_allocated;
+    size_t bitstream_allocated;
     uint8_t *bitstream_cache;
 };
 
@@ -321,8 +321,8 @@ static int dxva2_av1_decode_slice(AVCodecContext *avctx,
     }
 
     /* allocate an internal buffer */
-    tmp = av_fast_realloc(ctx->bitstream_cache, &ctx->bitstream_allocated,
-                          ctx_pic->bitstream_size + size);
+    tmp = av_realloc_reuse(ctx->bitstream_cache, &ctx->bitstream_allocated,
+                           ctx_pic->bitstream_size + size);
     if (!tmp) {
         return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index bd91cc1a05..c1a6529d3d 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -95,7 +95,7 @@ typedef struct FLACParseContext {
                                         can be verified                       */
     int end_padded;                /**< specifies if fifo_buf's end is padded */
     uint8_t *wrap_buf;             /**< general fifo read buffer when wrapped */
-    int wrap_buf_allocated_size;   /**< actual allocated size of the buffer   */
+    size_t wrap_buf_allocated_size;/**< actual allocated size of the buffer   */
     FLACFrameInfo last_fi;         /**< last decoded frame header info        */
     int last_fi_valid;             /**< set if last_fi is valid               */
 } FLACParseContext;
@@ -160,7 +160,7 @@ static size_t flac_fifo_space(const FifoBuffer *f)
  * about a memory barrier for SMP.
  */
 static uint8_t *flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len,
-                                    uint8_t **wrap_buf, int *allocated_size)
+                                    uint8_t **wrap_buf, size_t *allocated_size)
 {
     FifoBuffer   *f   = &fpc->fifo_buf;
     uint8_t *start    = f->rptr + offset;
@@ -171,7 +171,7 @@ static uint8_t *flac_fifo_read_wrap(FLACParseContext *fpc, int offset, int len,
     if (f->end - start >= len)
         return start;
 
-    tmp_buf = av_fast_realloc(*wrap_buf, allocated_size, len);
+    tmp_buf = av_realloc_reuse(*wrap_buf, allocated_size, len);
 
     if (!tmp_buf) {
         av_log(fpc->avctx, AV_LOG_ERROR,
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 90944177c7..4fe71ec587 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -463,7 +463,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
             if (new_size >= INT_MAX / sizeof(*pkt->nals))
                 return AVERROR(ENOMEM);
 
-            tmp = av_fast_realloc(pkt->nals, &pkt->nal_buffer_size, new_size * sizeof(*pkt->nals));
+            tmp = av_realloc_reuse(pkt->nals, &pkt->nal_buffer_size, new_size * sizeof(*pkt->nals));
             if (!tmp)
                 return AVERROR(ENOMEM);
 
diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h
index 787ce971ee..ae5e298fe8 100644
--- a/libavcodec/h2645_parse.h
+++ b/libavcodec/h2645_parse.h
@@ -84,7 +84,7 @@ typedef struct H2645Packet {
     H2645RBSP rbsp;
     int nb_nals;
     int nals_allocated;
-    unsigned nal_buffer_size;
+    size_t nal_buffer_size;
 } H2645Packet;
 
 /**
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index bd576fdd3a..10c1b4001e 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -70,7 +70,7 @@ typedef struct AOMEncoderContext {
     struct aom_codec_ctx encoder;
     struct aom_image rawimg;
     struct aom_fixed_buf twopass_stats;
-    unsigned twopass_stats_size;
+    size_t twopass_stats_size;
     struct FrameListData *coded_frame_list;
     int cpu_used;
     int auto_alt_ref;
@@ -1201,10 +1201,10 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
         case AOM_CODEC_STATS_PKT:
         {
             struct aom_fixed_buf *stats = &ctx->twopass_stats;
-            uint8_t *tmp = av_fast_realloc(stats->buf,
-                                           &ctx->twopass_stats_size,
-                                           stats->sz +
-                                           pkt->data.twopass_stats.sz);
+            uint8_t *tmp = av_realloc_reuse(stats->buf,
+                                            &ctx->twopass_stats_size,
+                                            stats->sz +
+                                            pkt->data.twopass_stats.sz);
             if (!tmp) {
                 av_freep(&stats->buf);
                 stats->sz = 0;
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index 0601efed2c..6ce08a6fbb 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -45,6 +45,7 @@ typedef struct librav1eContext {
 
     uint8_t *pass_data;
     size_t pass_pos;
+    size_t pass_size_allocated;
     int pass_size;
 
     AVDictionary *rav1e_opts;
@@ -116,8 +117,8 @@ static int get_stats(AVCodecContext *avctx, int eos)
         return 0;
 
     if (!eos) {
-        uint8_t *tmp = av_fast_realloc(ctx->pass_data, &ctx->pass_size,
-                                      ctx->pass_pos + buf->len);
+        uint8_t *tmp = av_realloc_reuse(ctx->pass_data, &ctx->pass_size_allocated,
+                                        ctx->pass_pos + buf->len);
         if (!tmp) {
             rav1e_data_unref(buf);
             return AVERROR(ENOMEM);
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index da16c6372e..bdaa03cbe6 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -46,6 +46,7 @@
 typedef struct TheoraContext {
     th_enc_ctx *t_state;
     uint8_t    *stats;
+    size_t      stats_size_allocated;
     int         stats_size;
     int         stats_offset;
     int         uv_hshift;
@@ -100,8 +101,8 @@ static int get_stats(AVCodecContext *avctx, int eos)
         return AVERROR_EXTERNAL;
     }
     if (!eos) {
-        void *tmp = av_fast_realloc(h->stats, &h->stats_size,
-                                   h->stats_offset + bytes);
+        void *tmp = av_realloc_reuse(h->stats, &h->stats_size_allocated,
+                                     h->stats_offset + bytes);
         if (!tmp)
             return AVERROR(ENOMEM);
         h->stats = tmp;
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 667cffc200..2d99b65ab0 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -80,7 +80,7 @@ typedef struct VPxEncoderContext {
     struct vpx_image rawimg_alpha;
     uint8_t is_alpha;
     struct vpx_fixed_buf twopass_stats;
-    unsigned twopass_stats_size;
+    size_t twopass_stats_size;
     int deadline; //i.e., RT/GOOD/BEST
     uint64_t sse[4];
     int have_sse; /**< true if we have pending sse[] */
@@ -1368,10 +1368,10 @@ static int queue_frames(AVCodecContext *avctx, struct vpx_codec_ctx *encoder,
             uint8_t *tmp;
             if (!pkt_out)
                 break;
-            tmp = av_fast_realloc(stats->buf,
-                                  &ctx->twopass_stats_size,
-                                  stats->sz +
-                                  pkt->data.twopass_stats.sz);
+            tmp = av_realloc_reuse(stats->buf,
+                                   &ctx->twopass_stats_size,
+                                   stats->sz +
+                                   pkt->data.twopass_stats.sz);
             if (!tmp) {
                 av_freep(&stats->buf);
                 stats->sz = 0;
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index ca0b5a145b..bbb013a698 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -359,7 +359,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
 
     if (frame) {
         x264_sei_t *sei = &x4->pic.extra_sei;
-        unsigned int sei_data_size = 0;
+        size_t sei_data_size = 0;
 
         for (i = 0; i < x4->pic.img.i_plane; i++) {
             x4->pic.img.plane[i]    = frame->data[i];
@@ -494,7 +494,8 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
                 x264_sei_payload_t *sei_payload;
                 if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
                     continue;
-                tmp = av_fast_realloc(sei->payloads, &sei_data_size, (sei->num_payloads + 1) * sizeof(*sei_payload));
+                tmp = av_realloc_reuse(sei->payloads, &sei_data_size,
+                                       (sei->num_payloads + 1) * sizeof(*sei_payload));
                 if (!tmp) {
                     free_picture(ctx);
                     return AVERROR(ENOMEM);
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 4aa96e1f2d..fa54db25bd 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -54,7 +54,7 @@ typedef struct libx265Context {
     AVDictionary *x265_opts;
 
     void *sei_data;
-    int sei_data_size;
+    size_t sei_data_size;
     int udu_sei;
 
     /**
@@ -555,9 +555,9 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                 if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
                     continue;
 
-                tmp = av_fast_realloc(ctx->sei_data,
-                        &ctx->sei_data_size,
-                        (sei->numPayloads + 1) * sizeof(*sei_payload));
+                tmp = av_realloc_reuse(ctx->sei_data,
+                                       &ctx->sei_data_size,
+                                       (sei->numPayloads + 1) * sizeof(*sei_payload));
                 if (!tmp) {
                     av_freep(&x265pic.userData);
                     av_freep(&x265pic.quantOffsets);
diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index 7aa74d7c9d..caeeba57e3 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -76,7 +76,7 @@ typedef struct {
     ASSStyle *ass_dialog_style;
     StyleBox *style_attributes;
     unsigned  count;
-    unsigned  style_attributes_bytes_allocated;
+    size_t  style_attributes_bytes_allocated;
     StyleBox  style_attributes_temp;
     AVBPrint buffer;
     HighlightBox hlit;
@@ -354,9 +354,9 @@ static int mov_text_style_start(MovTextContext *s)
 
         // last style != defaults, end the style entry and start a new one
         if (s->count + 1 > FFMIN(SIZE_MAX / sizeof(*s->style_attributes), UINT16_MAX) ||
-            !(tmp = av_fast_realloc(s->style_attributes,
-                                    &s->style_attributes_bytes_allocated,
-                                    (s->count + 1) * sizeof(*s->style_attributes)))) {
+            !(tmp = av_realloc_reuse(s->style_attributes,
+                                     &s->style_attributes_bytes_allocated,
+                                     (s->count + 1) * sizeof(*s->style_attributes)))) {
             mov_text_cleanup(s);
             av_bprint_clear(&s->buffer);
             s->box_flags &= ~STYL_BOX;
diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c
index fbaedf0b6b..5bfef4d2d6 100644
--- a/libavcodec/nvdec.c
+++ b/libavcodec/nvdec.c
@@ -677,8 +677,8 @@ int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
     NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
     void *tmp;
 
-    tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
-                          (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
+    tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated,
+                           (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
     if (!tmp)
         return AVERROR(ENOMEM);
     ctx->slice_offsets = tmp;
diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h
index 66f3ca59e7..ce475702e2 100644
--- a/libavcodec/nvdec.h
+++ b/libavcodec/nvdec.h
@@ -58,12 +58,12 @@ typedef struct NVDECContext {
 
     uint8_t      *bitstream;
     int           bitstream_len;
-    unsigned int  bitstream_allocated;
+    size_t        bitstream_allocated;
     uint8_t      *bitstream_internal;
 
     unsigned     *slice_offsets;
     int           nb_slices;
-    unsigned int  slice_offsets_allocated;
+    size_t        slice_offsets_allocated;
 
     int           supports_444;
 } NVDECContext;
diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
index 3bbcd76123..1409672748 100644
--- a/libavcodec/nvdec_av1.c
+++ b/libavcodec/nvdec_av1.c
@@ -293,8 +293,8 @@ static int nvdec_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
 
     ctx->nb_slices = frame_header->tile_cols * frame_header->tile_rows;
 
-    tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
-                          ctx->nb_slices * 2 * sizeof(*ctx->slice_offsets));
+    tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated,
+                           ctx->nb_slices * 2 * sizeof(*ctx->slice_offsets));
     if (!tmp) {
         return AVERROR(ENOMEM);
     }
@@ -313,8 +313,8 @@ static int nvdec_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
         return 0;
     }
 
-    tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
-                          ctx->bitstream_len + size);
+    tmp = av_realloc_reuse(ctx->bitstream_internal, &ctx->bitstream_allocated,
+                           ctx->bitstream_len + size);
     if (!tmp) {
         return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/nvdec_h264.c b/libavcodec/nvdec_h264.c
index 116bd4fb5d..1f95470ce3 100644
--- a/libavcodec/nvdec_h264.c
+++ b/libavcodec/nvdec_h264.c
@@ -137,14 +137,14 @@ static int nvdec_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
     const H264SliceContext *sl = &h->slice_ctx[0];
     void *tmp;
 
-    tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated,
-                          ctx->bitstream_len + size + 3);
+    tmp = av_realloc_reuse(ctx->bitstream, &ctx->bitstream_allocated,
+                           ctx->bitstream_len + size + 3);
     if (!tmp)
         return AVERROR(ENOMEM);
     ctx->bitstream = tmp;
 
-    tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
-                          (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
+    tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated,
+                           (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
     if (!tmp)
         return AVERROR(ENOMEM);
     ctx->slice_offsets = tmp;
diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c
index cd549d2ef6..002e8486c9 100644
--- a/libavcodec/nvdec_hevc.c
+++ b/libavcodec/nvdec_hevc.c
@@ -273,14 +273,14 @@ static int nvdec_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
     NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
     void *tmp;
 
-    tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated,
-                          ctx->bitstream_len + size + 3);
+    tmp = av_realloc_reuse(ctx->bitstream, &ctx->bitstream_allocated,
+                           ctx->bitstream_len + size + 3);
     if (!tmp)
         return AVERROR(ENOMEM);
     ctx->bitstream = tmp;
 
-    tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
-                          (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
+    tmp = av_realloc_reuse(ctx->slice_offsets, &ctx->slice_offsets_allocated,
+                           (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
     if (!tmp)
         return AVERROR(ENOMEM);
     ctx->slice_offsets = tmp;
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 11bd21f365..64d130fd5d 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -2202,9 +2202,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame)
         }
 
         if (a53_data) {
-            void *tmp = av_fast_realloc(ctx->sei_data,
-                                        &ctx->sei_data_size,
-                                        (sei_count + 1) * sizeof(*ctx->sei_data));
+            void *tmp = av_realloc_reuse(ctx->sei_data,
+                                         &ctx->sei_data_size,
+                                         (sei_count + 1) * sizeof(*ctx->sei_data));
             if (!tmp) {
                 av_free(a53_data);
                 res = AVERROR(ENOMEM);
@@ -2228,9 +2228,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame)
         }
 
         if (tc_data) {
-            void *tmp = av_fast_realloc(ctx->sei_data,
-                                        &ctx->sei_data_size,
-                                        (sei_count + 1) * sizeof(*ctx->sei_data));
+            void *tmp = av_realloc_reuse(ctx->sei_data,
+                                         &ctx->sei_data_size,
+                                         (sei_count + 1) * sizeof(*ctx->sei_data));
             if (!tmp) {
                 av_free(tc_data);
                 res = AVERROR(ENOMEM);
@@ -2255,9 +2255,9 @@ static int prepare_sei_data_array(AVCodecContext *avctx, const AVFrame *frame)
         if (side_data->type != AV_FRAME_DATA_SEI_UNREGISTERED)
             continue;
 
-        tmp = av_fast_realloc(ctx->sei_data,
-                              &ctx->sei_data_size,
-                              (sei_count + 1) * sizeof(*ctx->sei_data));
+        tmp = av_realloc_reuse(ctx->sei_data,
+                               &ctx->sei_data_size,
+                               (sei_count + 1) * sizeof(*ctx->sei_data));
         if (!tmp) {
             res = AVERROR(ENOMEM);
             goto error;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 9eb129952e..17a80e2706 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -174,7 +174,7 @@ typedef struct NvencContext
     AVFifo *timestamp_list;
 
     NV_ENC_SEI_PAYLOAD *sei_data;
-    int sei_data_size;
+    size_t sei_data_size;
 
     struct {
         void *ptr;
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 49de7e6a57..ba9af5daed 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -221,9 +221,9 @@ int ff_combine_frame(ParseContext *pc, int next,
 
     /* copy into buffer end return */
     if (next == END_NOT_FOUND) {
-        void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size,
-                                           *buf_size + pc->index +
-                                           AV_INPUT_BUFFER_PADDING_SIZE);
+        void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size,
+                                            *buf_size + pc->index +
+                                            AV_INPUT_BUFFER_PADDING_SIZE);
 
         if (!new_buffer) {
             av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", *buf_size + pc->index + AV_INPUT_BUFFER_PADDING_SIZE);
@@ -243,9 +243,9 @@ int ff_combine_frame(ParseContext *pc, int next,
 
     /* append to buffer */
     if (pc->index) {
-        void *new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size,
-                                           next + pc->index +
-                                           AV_INPUT_BUFFER_PADDING_SIZE);
+        void *new_buffer = av_realloc_reuse(pc->buffer, &pc->buffer_size,
+                                            next + pc->index +
+                                            AV_INPUT_BUFFER_PADDING_SIZE);
         if (!new_buffer) {
             av_log(NULL, AV_LOG_ERROR, "Failed to reallocate parser buffer to %d\n", next + pc->index + AV_INPUT_BUFFER_PADDING_SIZE);
             pc->overread_index =
diff --git a/libavcodec/parser.h b/libavcodec/parser.h
index 2cee5ae4ff..908800fcce 100644
--- a/libavcodec/parser.h
+++ b/libavcodec/parser.h
@@ -29,7 +29,7 @@ typedef struct ParseContext{
     uint8_t *buffer;
     int index;
     int last_index;
-    unsigned int buffer_size;
+    size_t buffer_size;
     uint32_t state;             ///< contains the last few bytes in MSB order
     int frame_start_found;
     int overread;               ///< the number of bytes which where irreversibly read from the next frame
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 1b2abd76b1..36b7349be3 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -97,7 +97,7 @@ typedef struct ShortenContext {
     uint8_t *bitstream;
     int bitstream_size;
     int bitstream_index;
-    unsigned int allocated_bitstream_size;
+    size_t allocated_bitstream_size;
     int header_size;
     uint8_t header[OUT_BUFFER_SIZE];
     int version;
@@ -535,8 +535,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (s->max_framesize == 0) {
         void *tmp_ptr;
         s->max_framesize = 8192; // should hopefully be enough for the first header
-        tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
-                                  s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE);
+        tmp_ptr = av_realloc_reuse(s->bitstream, &s->allocated_bitstream_size,
+                                   s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE);
         if (!tmp_ptr) {
             s->max_framesize = 0;
             av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
@@ -585,8 +585,8 @@ static int shorten_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             void *tmp_ptr;
 
             max_framesize = FFMAX(s->max_framesize, s->blocksize * s->channels * 8);
-            tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
-                                      max_framesize + AV_INPUT_BUFFER_PADDING_SIZE);
+            tmp_ptr = av_realloc_reuse(s->bitstream, &s->allocated_bitstream_size,
+                                       max_framesize + AV_INPUT_BUFFER_PADDING_SIZE);
             if (!tmp_ptr) {
                 av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
                 return AVERROR(ENOMEM);
diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c
index 0bb793c010..a201b3024a 100644
--- a/libavcodec/vdpau.c
+++ b/libavcodec/vdpau.c
@@ -388,8 +388,8 @@ int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx,
 {
     VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
 
-    buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
-                              (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
+    buffers = av_realloc_reuse(buffers, &pic_ctx->bitstream_buffers_allocated,
+                               (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
     if (!buffers)
         return AVERROR(ENOMEM);
 
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 347576e0c3..b0e97c0a6d 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -104,7 +104,7 @@ struct vdpau_picture_context {
     /**
      * Allocated size of the bitstream_buffers table.
      */
-    int bitstream_buffers_allocated;
+    size_t bitstream_buffers_allocated;
 
     /**
      * Useful bitstream buffers in the bitstream buffers table.
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 1b1be8ddb4..c8d96f6794 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -76,9 +76,9 @@ int ff_videotoolbox_buffer_copy(VTContext *vtctx,
 {
     void *tmp;
 
-    tmp = av_fast_realloc(vtctx->bitstream,
-                         &vtctx->allocated_size,
-                         size);
+    tmp = av_realloc_reuse(vtctx->bitstream,
+                           &vtctx->allocated_size,
+                           size);
 
     if (!tmp)
         return AVERROR(ENOMEM);
@@ -432,9 +432,9 @@ static int videotoolbox_common_decode_slice(AVCodecContext *avctx,
     VTContext *vtctx = avctx->internal->hwaccel_priv_data;
     void *tmp;
 
-    tmp = av_fast_realloc(vtctx->bitstream,
-                          &vtctx->allocated_size,
-                          vtctx->bitstream_size+size+4);
+    tmp = av_realloc_reuse(vtctx->bitstream,
+                           &vtctx->allocated_size,
+                           vtctx->bitstream_size+size+4);
     if (!tmp)
         return AVERROR(ENOMEM);
 
diff --git a/libavcodec/vt_internal.h b/libavcodec/vt_internal.h
index 9502d7c7dc..9cfd4722e5 100644
--- a/libavcodec/vt_internal.h
+++ b/libavcodec/vt_internal.h
@@ -30,7 +30,7 @@ typedef struct VTContext {
     int                         bitstream_size;
 
     // The reference size used for fast reallocation.
-    int                         allocated_size;
+    size_t                      allocated_size;
 
     // The core video buffer
     CVImageBufferRef            frame;
