nut: Fix unchecked allocations

CC: libav-stable@libav.org
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
This commit is contained in:
Derek Buitenhuis 2013-10-22 16:11:11 +01:00
parent 3511d4fc97
commit b1fcdc08ce
4 changed files with 16 additions and 4 deletions

View File

@ -185,11 +185,17 @@ int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b)
return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32); return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32);
} }
void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts) int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
{ {
Syncpoint *sp = av_mallocz(sizeof(Syncpoint)); Syncpoint *sp = av_mallocz(sizeof(Syncpoint));
struct AVTreeNode *node = av_tree_node_alloc(); struct AVTreeNode *node = av_tree_node_alloc();
if (!sp || !node) {
av_freep(&sp);
av_freep(&node);
return AVERROR(ENOMEM);
}
sp->pos = pos; sp->pos = pos;
sp->back_ptr = back_ptr; sp->back_ptr = back_ptr;
sp->ts = ts; sp->ts = ts;
@ -198,6 +204,8 @@ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
av_free(sp); av_free(sp);
av_free(node); av_free(node);
} }
return 0;
} }
static int enu_free(void *opaque, void *elem) static int enu_free(void *opaque, void *elem)

View File

@ -118,7 +118,7 @@ void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val);
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); int64_t ff_lsb2full(StreamContext *stream, int64_t lsb);
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b); int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b);
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b); int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b);
void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts);
void ff_nut_free_sp(NUTContext *nut); void ff_nut_free_sp(NUTContext *nut);
extern const Dispositions ff_nut_dispositions[]; extern const Dispositions ff_nut_dispositions[];

View File

@ -532,6 +532,7 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
AVFormatContext *s = nut->avf; AVFormatContext *s = nut->avf;
AVIOContext *bc = s->pb; AVIOContext *bc = s->pb;
int64_t end, tmp; int64_t end, tmp;
int ret;
nut->last_syncpoint_pos = avio_tell(bc) - 8; nut->last_syncpoint_pos = avio_tell(bc) - 8;
@ -553,7 +554,9 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr)
*ts = tmp / s->nb_streams * *ts = tmp / s->nb_streams *
av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE; av_q2d(nut->time_base[tmp % s->nb_streams]) * AV_TIME_BASE;
ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts);
if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts)) < 0)
return ret;
return 0; return 0;
} }

View File

@ -815,7 +815,8 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos) >> 4 : 0); ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos) >> 4 : 0);
put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE); put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts); if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts)) < 0)
return ret;
} }
assert(nus->last_pts != AV_NOPTS_VALUE); assert(nus->last_pts != AV_NOPTS_VALUE);