From a4798a5d5109cd9c1b5682efe19660e825da97e6 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sat, 27 Nov 2021 10:50:47 +0100 Subject: all: Use av_memdup() where appropriate Reviewed-by: Nicolas George Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 4 +--- libavcodec/dvbsubdec.c | 8 ++------ libavcodec/g723_1enc.c | 3 +-- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/decode.c b/libavcodec/decode.c index c44724d150..52bf5dcd33 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1104,12 +1104,10 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) avctx->sw_pix_fmt = fmt[n - 1]; } - choices = av_malloc_array(n + 1, sizeof(*choices)); + choices = av_memdup(fmt, (n + 1) * sizeof(*choices)); if (!choices) return AV_PIX_FMT_NONE; - memcpy(choices, fmt, (n + 1) * sizeof(*choices)); - for (;;) { // Remove the previous hwaccel, if there was one. hwaccel_uninit(avctx); diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index d192f3251d..81ccaf4c57 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -823,14 +823,12 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou } memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(*clut_table)); - rect->data[0] = av_malloc(region->buf_size); + rect->data[0] = av_memdup(region->pbuf, region->buf_size); if (!rect->data[0]) { ret = AVERROR(ENOMEM); goto fail; } - memcpy(rect->data[0], region->pbuf, region->buf_size); - if ((clut == &default_clut && ctx->compute_clut < 0) || ctx->compute_clut == 1) { if (!region->has_computed_clut) { compute_default_clut(ctx, region->computed_clut, rect, rect->w, rect->h); @@ -1074,12 +1072,10 @@ static int dvbsub_parse_clut_segment(AVCodecContext *avctx, clut = get_clut(ctx, clut_id); if (!clut) { - clut = av_malloc(sizeof(*clut)); + clut = av_memdup(&default_clut, sizeof(*clut)); if (!clut) return AVERROR(ENOMEM); - memcpy(clut, &default_clut, sizeof(*clut)); - clut->id = clut_id; clut->version = -1; diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c index 2b3cccee09..2a8149b4cd 100644 --- a/libavcodec/g723_1enc.c +++ b/libavcodec/g723_1enc.c @@ -1116,10 +1116,9 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, HFParam hf[4]; /* duplicate input */ - start = in = av_malloc(frame->nb_samples * sizeof(int16_t)); + start = in = av_memdup(frame->data[0], frame->nb_samples * sizeof(int16_t)); if (!in) return AVERROR(ENOMEM); - memcpy(in, frame->data[0], frame->nb_samples * sizeof(int16_t)); highpass_filter(in, &p->hpf_fir_mem, &p->hpf_iir_mem); -- cgit v1.2.3