---
libavformat/oggparsetheora.c | 7 +++---
libavformat/oggparsevorbis.c | 2 +-
libavformat/rdt.c | 12 +++++-----
libavformat/rtmphttp.c | 9 ++++----
libavformat/rtmpproto.c | 45 +++++++++++++++++++-------------------
libavformat/rtpdec_asf.c | 9 +++-----
libavformat/rtpdec_qt.c | 9 ++++----
libavformat/smacker.c | 9 +++-----
libavformat/smoothstreamingenc.c | 8 ++++---
libavformat/utils.c | 7 +++---
10 files changed, 57 insertions(+), 60 deletions(-)
diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c
index ed31d53..7dbc42d 100644
--- a/libavformat/oggparsetheora.c
+++ b/libavformat/oggparsetheora.c
@@ -42,7 +42,7 @@ theora_header (AVFormatContext * s, int idx)
struct ogg_stream *os = ogg->streams + idx;
AVStream *st = s->streams[idx];
struct theora_params *thp = os->private;
- int cds = st->codec->extradata_size + os->psize + 2;
+ int cds = st->codec->extradata_size + os->psize + 2, err;
uint8_t *cdp;
if(!(os->buf[os->pstart] & 0x80))
@@ -123,8 +123,9 @@ theora_header (AVFormatContext * s, int idx)
return -1;
}
- st->codec->extradata = av_realloc (st->codec->extradata,
- cds + FF_INPUT_BUFFER_PADDING_SIZE);
+ if ((err = av_reallocp(&st->codec->extradata, cds +
+ FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+ return err;
cdp = st->codec->extradata + st->codec->extradata_size;
*cdp++ = os->psize >> 8;
*cdp++ = os->psize & 0xff;
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index db462fc..4bb0afd 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -188,7 +188,7 @@ fixup_vorbis_headers(AVFormatContext * as, struct
oggvorbis_private *priv,
offset += priv->len[i];
av_freep(&priv->packet[i]);
}
- *buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);
+ av_reallocp(buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);
return offset;
}
diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index a8367e5..691460b 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -409,6 +409,7 @@ rdt_parse_sdp_line (AVFormatContext *s, int st_index,
{
AVStream *stream = s->streams[st_index];
const char *p = line;
+ int err;
if (av_strstart(p, "OpaqueData:buffer;", &p)) {
rdt->mlti_data = rdt_parse_b64buf(&rdt->mlti_data_size, p);
@@ -422,12 +423,11 @@ rdt_parse_sdp_line (AVFormatContext *s, int st_index,
int count = s->streams[n]->index + 1;
if (first == -1) first = n;
if (rdt->nb_rmst < count) {
- RMStream **rmst= av_realloc(rdt->rmst,
count*sizeof(*rmst));
- if (!rmst)
- return AVERROR(ENOMEM);
- memset(rmst + rdt->nb_rmst, 0,
- (count - rdt->nb_rmst) * sizeof(*rmst));
- rdt->rmst = rmst;
+ if ((err = av_reallocp(&rdt->rmst, count *
+ sizeof(rdt->rmst))) < 0)
+ return err;
+ memset(rdt->rmst + rdt->nb_rmst, 0,
+ (count - rdt->nb_rmst) * sizeof(rdt->rmst));
rdt->nb_rmst = count;
}
rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream();
diff --git a/libavformat/rtmphttp.c b/libavformat/rtmphttp.c
index e67abba..a06ca3c 100644
--- a/libavformat/rtmphttp.c
+++ b/libavformat/rtmphttp.c
@@ -84,15 +84,14 @@ static int rtmp_http_send_cmd(URLContext *h, const char
*cmd)
static int rtmp_http_write(URLContext *h, const uint8_t *buf, int size)
{
+ int err;
+
RTMP_HTTPContext *rt = h->priv_data;
- void *ptr;
if (rt->out_size + size > rt->out_capacity) {
rt->out_capacity = (rt->out_size + size) * 2;
- ptr = av_realloc(rt->out_data, rt->out_capacity);
- if (!ptr)
- return AVERROR(ENOMEM);
- rt->out_data = ptr;
+ if ((err = av_reallocp(&rt->out_data, rt->out_capacity)) < 0)
+ return err;
}
memcpy(rt->out_data + rt->out_size, buf, size);
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 58cedef..b6f67a6 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -148,15 +148,13 @@ static const uint8_t rtmp_server_key[] = {
static int add_tracked_method(RTMPContext *rt, const char *name, int id)
{
- void *ptr;
+ int err;
if (rt->nb_tracked_methods + 1 > rt->tracked_methods_size) {
rt->tracked_methods_size = (rt->nb_tracked_methods + 1) * 2;
- ptr = av_realloc(rt->tracked_methods,
- rt->tracked_methods_size *
sizeof(*rt->tracked_methods));
- if (!ptr)
- return AVERROR(ENOMEM);
- rt->tracked_methods = ptr;
+ if ((err = av_reallocp(&rt->tracked_methods, rt->tracked_methods_size *
+ sizeof(*rt->tracked_methods))) < 0)
+ return err;
}
rt->tracked_methods[rt->nb_tracked_methods].name = av_strdup(name);
@@ -2007,7 +2005,7 @@ static int handle_notify(URLContext *s, RTMPPacket *pkt) {
GetByteContext gbc;
PutByteContext pbc;
uint32_t ts;
- int old_flv_size;
+ int old_flv_size, err;
const uint8_t *datatowrite;
unsigned datatowritelength;
@@ -2041,9 +2039,9 @@ static int handle_notify(URLContext *s, RTMPPacket *pkt) {
rt->flv_off = 0;
}
- cp = av_realloc(rt->flv_data, rt->flv_size);
- if (!cp)
- return AVERROR(ENOMEM);
+ cp = rt->flv_data;
+ if ((err = av_reallocp(&cp, rt->flv_size)) < 0)
+ return err;
rt->flv_data = cp;
bytestream2_init_writer(&pbc, cp, rt->flv_size);
bytestream2_skip_p(&pbc, old_flv_size);
@@ -2123,7 +2121,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext
*rt, RTMPPacket *pkt)
static int get_packet(URLContext *s, int for_header)
{
RTMPContext *rt = s->priv_data;
- int ret;
+ int ret, err;
uint8_t *p;
const uint8_t *next;
uint32_t data_size;
@@ -2180,14 +2178,15 @@ static int get_packet(URLContext *s, int for_header)
// generate packet header and put data into buffer for FLV demuxer
rt->flv_off = 0;
rt->flv_size = rpkt.data_size + 15;
- rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);
- bytestream_put_byte(&p, rpkt.type);
- bytestream_put_be24(&p, rpkt.data_size);
- bytestream_put_be24(&p, ts);
- bytestream_put_byte(&p, ts >> 24);
- bytestream_put_be24(&p, 0);
- bytestream_put_buffer(&p, rpkt.data, rpkt.data_size);
- bytestream_put_be32(&p, 0);
+ if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0)
+ return err;
+ bytestream_put_byte(&rt->flv_data, rpkt.type);
+ bytestream_put_be24(&rt->flv_data, rpkt.data_size);
+ bytestream_put_be24(&rt->flv_data, ts);
+ bytestream_put_byte(&rt->flv_data, ts >> 24);
+ bytestream_put_be24(&rt->flv_data, 0);
+ bytestream_put_buffer(&rt->flv_data, rpkt.data, rpkt.data_size);
+ bytestream_put_be32(&rt->flv_data, 0);
ff_rtmp_packet_destroy(&rpkt);
return 0;
} else if (rpkt.type == RTMP_PT_NOTIFY) {
@@ -2202,7 +2201,8 @@ static int get_packet(URLContext *s, int for_header)
// we got raw FLV data, make it available for FLV demuxer
rt->flv_off = 0;
rt->flv_size = rpkt.data_size;
- rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
+ if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0)
+ return err;
/* rewrite timestamps */
next = rpkt.data;
ts = rpkt.timestamp;
@@ -2266,7 +2266,7 @@ static int rtmp_open(URLContext *s, const char *uri, int
flags)
uint8_t buf[2048];
int port;
AVDictionary *opts = NULL;
- int ret;
+ int ret, err;
if (rt->listen_timeout > 0)
rt->listen = 1;
@@ -2464,7 +2464,8 @@ reconnect:
if (rt->is_input) {
// generate FLV header for demuxer
rt->flv_size = 13;
- rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
+ if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0)
+ return err;
rt->flv_off = 0;
memcpy(rt->flv_data, "FLV\1\5\0\0\0\011\0\0\0\0", rt->flv_size);
} else {
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index e425650..369d9fd 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -172,7 +172,7 @@ static int asfrtp_parse_packet(AVFormatContext *s,
PayloadContext *asf,
int flags)
{
AVIOContext *pb = &asf->pb;
- int res, mflags, len_off;
+ int res, mflags, len_off, err;
RTSPState *rt = s->priv_data;
if (!rt->asf_ctx)
@@ -239,14 +239,11 @@ static int asfrtp_parse_packet(AVFormatContext *s,
PayloadContext *asf,
int cur_len = start_off + len_off - off;
int prev_len = out_len;
- void *newmem;
out_len += cur_len;
if (FFMIN(cur_len, len - off) < 0)
return -1;
- newmem = av_realloc(asf->buf, out_len);
- if (!newmem)
- return -1;
- asf->buf = newmem;
+ if ((err = av_reallocp(&asf->buf, out_len)) < 0)
+ return err;
memcpy(asf->buf + prev_len, buf + off,
FFMIN(cur_len, len - off));
avio_skip(pb, cur_len);
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index af5a5e9..397a5fb 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -46,7 +46,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s,
PayloadContext *qt,
{
AVIOContext pb;
GetBitContext gb;
- int packing_scheme, has_payload_desc, has_packet_info, alen,
+ int packing_scheme, has_payload_desc, has_packet_info, alen, err,
has_marker_bit = flags & RTP_FLAG_MARKER;
if (qt->remaining) {
@@ -172,8 +172,9 @@ static int qt_rtp_parse_packet(AVFormatContext *s,
PayloadContext *qt,
switch (packing_scheme) {
case 3: /* one data packet spread over 1 or multiple RTP packets */
if (qt->pkt.size > 0 && qt->timestamp == *timestamp) {
- qt->pkt.data = av_realloc(qt->pkt.data, qt->pkt.size + alen +
- FF_INPUT_BUFFER_PADDING_SIZE);
+ if ((err = av_reallocp(&qt->pkt.data, qt->pkt.size + alen +
+ FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+ return err;
} else {
av_freep(&qt->pkt.data);
av_init_packet(&qt->pkt);
@@ -181,8 +182,6 @@ static int qt_rtp_parse_packet(AVFormatContext *s,
PayloadContext *qt,
qt->pkt.size = 0;
qt->timestamp = *timestamp;
}
- if (!qt->pkt.data)
- return AVERROR(ENOMEM);
memcpy(qt->pkt.data + qt->pkt.size, buf + avio_tell(&pb), alen);
qt->pkt.size += alen;
if (has_marker_bit) {
diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index cd4353a..0fe835e 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -240,7 +240,7 @@ static int smacker_read_header(AVFormatContext *s)
static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
{
SmackerContext *smk = s->priv_data;
- int flags;
+ int flags, err;
int ret;
int i;
int frame_size = 0;
@@ -305,7 +305,6 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket
*pkt)
for(i = 0; i < 7; i++) {
if(flags & 1) {
uint32_t size;
- uint8_t *tmpbuf;
size = avio_rl32(s->pb) - 4;
if (!size || size > frame_size) {
@@ -315,10 +314,8 @@ static int smacker_read_packet(AVFormatContext *s,
AVPacket *pkt)
frame_size -= size;
frame_size -= 4;
smk->curstream++;
- tmpbuf = av_realloc(smk->bufs[smk->curstream], size);
- if (!tmpbuf)
- return AVERROR(ENOMEM);
- smk->bufs[smk->curstream] = tmpbuf;
+ if ((err = av_reallocp(&smk->bufs[smk->curstream], size)) < 0)
+ return err;
smk->buf_sizes[smk->curstream] = size;
ret = avio_read(s->pb, smk->bufs[smk->curstream], size);
if(ret != size)
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index d26af05..b0f63d2 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -443,12 +443,14 @@ fail:
static int add_fragment(OutputStream *os, const char *file, const char
*infofile, int64_t start_time, int64_t duration, int64_t start_pos, int64_t
size)
{
+ int err;
+
Fragment *frag;
if (os->nb_fragments >= os->fragments_size) {
os->fragments_size = (os->fragments_size + 1) * 2;
- os->fragments = av_realloc(os->fragments,
sizeof(*os->fragments)*os->fragments_size);
- if (!os->fragments)
- return AVERROR(ENOMEM);
+ if ((err = av_reallocp(&os->fragments, sizeof(*os->fragments) *
+ os->fragments_size)) < 0)
+ return err;
}
frag = av_mallocz(sizeof(*frag));
if (!frag)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 10803ac..e0a94ec 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -241,7 +241,7 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat
**fmt,
{
AVProbeData pd = { filename ? filename : "", NULL, -offset };
unsigned char *buf = NULL;
- int ret = 0, probe_size;
+ int ret = 0, probe_size, err;
if (!max_probe_size) {
max_probe_size = PROBE_BUF_MAX;
@@ -265,7 +265,8 @@ int av_probe_input_buffer(AVIOContext *pb, AVInputFormat
**fmt,
}
/* read probe data */
- buf = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE);
+ if ((err = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)
+ return err;
if ((ret = avio_read(pb, buf + buf_offset, probe_size - buf_offset)) <
0) {
/* fail if error was not end of file, otherwise, lower score */
if (ret != AVERROR_EOF) {
@@ -456,7 +457,7 @@ static void probe_codec(AVFormatContext *s, AVStream *st,
const AVPacket *pkt)
--st->probe_packets;
if (pkt) {
- pd->buf = av_realloc(pd->buf,
pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
+ av_reallocp(&pd->buf, pd->buf_size + pkt->size +
AVPROBE_PADDING_SIZE);
memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
pd->buf_size += pkt->size;
memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
--
1.7.10.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel