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
95 95
96 // allocate sub and set values96 // allocate sub and set values
97 sub->rects = av_mallocz(sizeof(*sub->rects));97 sub->rects = av_mallocz(sizeof(*sub->rects));
98 if (!sub->rects)
99 return AVERROR(ENOMEM);
98 sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));100 sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
101 if (!sub->rects[0]) {
102 av_freep(&sub->rects);
103 return AVERROR(ENOMEM);
104 }
99 sub->num_rects = 1;105 sub->num_rects = 1;
100 sub->rects[0]->x = x; sub->rects[0]->y = y;106 sub->rects[0]->x = x; sub->rects[0]->y = y;
101 sub->rects[0]->w = w; sub->rects[0]->h = h;107 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
104 sub->rects[0]->pict.data[0] = av_malloc(w * h);110 sub->rects[0]->pict.data[0] = av_malloc(w * h);
105 sub->rects[0]->nb_colors = 4;111 sub->rects[0]->nb_colors = 4;
106 sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);112 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 }
107 120
108 // read palette121 // read palette
109 for (i = 0; i < sub->rects[0]->nb_colors; i++)122 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