all: Use av_memdup() where appropriate

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/375/head
Andreas Rheinhardt 3 years ago
parent b574fb472e
commit a4798a5d51
  1. 4
      libavcodec/decode.c
  2. 8
      libavcodec/dvbsubdec.c
  3. 3
      libavcodec/g723_1enc.c
  4. 6
      libavformat/hdsenc.c
  5. 3
      libavformat/mpegts.c
  6. 3
      libavformat/oggparsevorbis.c
  7. 3
      libavformat/rtsp.c
  8. 6
      libavutil/bprint.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);

@ -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;

@ -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);

@ -93,19 +93,17 @@ static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
if (os->nb_extra_packets >= FF_ARRAY_ELEMS(os->extra_packets))
return AVERROR_INVALIDDATA;
os->extra_packet_sizes[os->nb_extra_packets] = size;
os->extra_packets[os->nb_extra_packets] = av_malloc(size);
os->extra_packets[os->nb_extra_packets] = av_memdup(buf, size);
if (!os->extra_packets[os->nb_extra_packets])
return AVERROR(ENOMEM);
memcpy(os->extra_packets[os->nb_extra_packets], buf, size);
os->nb_extra_packets++;
} else if (type == 0x12) {
if (os->metadata)
return AVERROR_INVALIDDATA;
os->metadata_size = size - 11 - 4;
os->metadata = av_malloc(os->metadata_size);
os->metadata = av_memdup(buf + 11, os->metadata_size);
if (!os->metadata)
return AVERROR(ENOMEM);
memcpy(os->metadata, buf + 11, os->metadata_size);
}
buf += size;
buf_size -= size;

@ -938,10 +938,9 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
// audio track - add a second stream for this
AVStream *sub_st;
// priv_data cannot be shared between streams
PESContext *sub_pes = av_malloc(sizeof(*sub_pes));
PESContext *sub_pes = av_memdup(pes, sizeof(*sub_pes));
if (!sub_pes)
return AVERROR(ENOMEM);
memcpy(sub_pes, pes, sizeof(*sub_pes));
sub_st = avformat_new_stream(pes->stream, NULL);
if (!sub_st) {

@ -320,10 +320,9 @@ static int vorbis_header(AVFormatContext *s, int idx)
return priv->vp ? 0 : AVERROR_INVALIDDATA;
priv->len[pkt_type >> 1] = os->psize;
priv->packet[pkt_type >> 1] = av_mallocz(os->psize);
priv->packet[pkt_type >> 1] = av_memdup(os->buf + os->pstart, os->psize);
if (!priv->packet[pkt_type >> 1])
return AVERROR(ENOMEM);
memcpy(priv->packet[pkt_type >> 1], os->buf + os->pstart, os->psize);
if (os->buf[os->pstart] == 1) {
const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */
unsigned blocksize, bs0, bs1;

@ -387,10 +387,9 @@ static void copy_default_source_addrs(struct RTSPSource **addrs, int count,
int i;
for (i = 0; i < count; i++) {
rtsp_src = addrs[i];
rtsp_src2 = av_malloc(sizeof(*rtsp_src2));
rtsp_src2 = av_memdup(rtsp_src, sizeof(*rtsp_src));
if (!rtsp_src2)
continue;
memcpy(rtsp_src2, rtsp_src, sizeof(*rtsp_src));
dynarray_add(dest, dest_count, rtsp_src2);
}
}

@ -244,10 +244,8 @@ int av_bprint_finalize(AVBPrint *buf, char **ret_str)
str = buf->str;
buf->str = NULL;
} else {
str = av_malloc(real_size);
if (str)
memcpy(str, buf->str, real_size);
else
str = av_memdup(buf->str, real_size);
if (!str)
ret = AVERROR(ENOMEM);
}
*ret_str = str;

Loading…
Cancel
Save