From 1e34019d625d4b33a1767af70bc6c7e2c6b42a7f Mon Sep 17 00:00:00 2001
From: John Rummell <jrummell@chromium.org>
Date: Wed, 21 Jun 2017 14:39:20 -0700
Subject: [PATCH] libavformat/mov: Always use av_realloc() for
AVCodecParameters.extradata
Chromium uses tcmalloc which doesn't like mixing calls to posix_memalign()
and realloc(). This change updates mov.c to only use av_realloc() when
allocating memory for AVCodecParameters.extradata.
---
libavformat/mov.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
@@ -1652,9 +1652,10 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
atom.size += 8;
} else if (!st->codecpar->extradata_size) {
#define ALAC_EXTRADATA_SIZE 36
- st->codecpar->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codecpar->extradata)
- return AVERROR(ENOMEM);
+ uint64_t size = ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE;
+ if ((ret = av_reallocp(&st->codecpar->extradata, size)) < 0)
+ return ret;
+ memset(st->codecpar->extradata, 0, size);
st->codecpar->extradata_size = ALAC_EXTRADATA_SIZE;
AV_WB32(st->codecpar->extradata , ALAC_EXTRADATA_SIZE);
AV_WB32(st->codecpar->extradata + 4, MKTAG('a','l','a','c'));
@@ -2054,6 +2055,8 @@ static int mov_rewrite_dvd_sub_extradata(AVStream *st)
char buf[256] = {0};
uint8_t *src = st->codecpar->extradata;
int i;
+ uint64_t size;
+ int ret;
if (st->codecpar->extradata_size != 64)
return 0;
@@ -2075,9 +2078,9 @@ static int mov_rewrite_dvd_sub_extradata(AVStream *st)
av_freep(&st->codecpar->extradata);
st->codecpar->extradata_size = 0;
- st->codecpar->extradata = av_mallocz(strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codecpar->extradata)
- return AVERROR(ENOMEM);
+ size = strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE;
+ if ((ret = av_reallocp(&st->codecpar->extradata, size)) < 0)
+ return ret;
st->codecpar->extradata_size = strlen(buf);
memcpy(st->codecpar->extradata, buf, st->codecpar->extradata_size);
@@ -2392,9 +2395,9 @@ static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_freep(&st->codecpar->extradata);
st->codecpar->extradata_size = sc->extradata_size[0];
if (sc->extradata_size[0]) {
- st->codecpar->extradata = av_mallocz(sc->extradata_size[0] + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!st->codecpar->extradata)
- return AVERROR(ENOMEM);
+ uint64_t size = sc->extradata_size[0] + AV_INPUT_BUFFER_PADDING_SIZE;
+ if ((ret = av_reallocp(&st->codecpar->extradata, size)) < 0)
+ return ret;
memcpy(st->codecpar->extradata, sc->extradata[0], sc->extradata_size[0]);
}
--
2.14.1.342.g6490525c54-goog