History

xsub: Check memory allocation

Vittorio Giovara committed 11 years ago

Commit 522d9711 parent 83797da1 file · +13 −0Browse files

Unified · Split

libavcodec/xsubdec.c+13−0
@@ -95,7 +95,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 94 unmodified lines
9595
9696 // allocate sub and set values
9797 sub->rects = av_mallocz(sizeof(*sub->rects));
98+ if (!sub->rects)
99+ return AVERROR(ENOMEM);
98100 sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
101+ if (!sub->rects[0]) {
102+ av_freep(&sub->rects);
103+ return AVERROR(ENOMEM);
104+ }
99105 sub->num_rects = 1;
100106 sub->rects[0]->x = x; sub->rects[0]->y = y;
101107 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, · 2 unmodified lines
104110 sub->rects[0]->pict.data[0] = av_malloc(w * h);
105111 sub->rects[0]->nb_colors = 4;
106112 sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
113+ if (!sub->rects[0]->pict.data[0] || !sub->rects[0]->pict.data[1]) {
114+ av_freep(&sub->rects[0]->pict.data[1]);
115+ av_freep(&sub->rects[0]->pict.data[0]);
116+ av_freep(&sub->rects[0]);
117+ av_freep(&sub->rects);
118+ return AVERROR(ENOMEM);
119+ }
107120
108121 // read palette
109122 for (i = 0; i < sub->rects[0]->nb_colors; i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t