[FFmpeg-cvslog] xsub: Check memory allocation
Vittorio Giovara
git at videolan.org
Mon Jun 1 02:54:42 CEST 2015
ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Sun May 31 14:55:44 2015 +0200| [522d971c7f5921bebcea2fc50e67056afdabb951] | committer: Luca Barbato
xsub: Check memory allocation
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=522d971c7f5921bebcea2fc50e67056afdabb951
---
libavcodec/xsubdec.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index d01b410..a7dd7ee 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -95,7 +95,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
// allocate sub and set values
sub->rects = av_mallocz(sizeof(*sub->rects));
+ if (!sub->rects)
+ return AVERROR(ENOMEM);
sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
+ if (!sub->rects[0]) {
+ av_freep(&sub->rects);
+ return AVERROR(ENOMEM);
+ }
sub->num_rects = 1;
sub->rects[0]->x = x; sub->rects[0]->y = y;
sub->rects[0]->w = w; sub->rects[0]->h = h;
@@ -104,6 +110,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
sub->rects[0]->pict.data[0] = av_malloc(w * h);
sub->rects[0]->nb_colors = 4;
sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
+ if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) {
+ av_freep(&sub->rects[0]->pict.data[1]);
+ av_freep(&sub->rects[0]->pict.data[0]);
+ av_freep(&sub->rects[0]);
+ av_freep(&sub->rects);
+ return AVERROR(ENOMEM);
+ }
// read palette
for (i = 0; i < sub->rects[0]->nb_colors; i++)
More information about the ffmpeg-cvslog
mailing list