Browse code

apedec: check for filter buffer allocation failure (cherry picked from commit 7500781313d11b37772c05a28da20fbc112db478)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Justin Ruggles authored on 2011/10/12 00:47:15
Showing 1 changed files
... ...
@@ -163,6 +163,18 @@ typedef struct APEContext {
163 163
 
164 164
 // TODO: dsputilize
165 165
 
166
+static av_cold int ape_decode_close(AVCodecContext * avctx)
167
+{
168
+    APEContext *s = avctx->priv_data;
169
+    int i;
170
+
171
+    for (i = 0; i < APE_FILTER_LEVELS; i++)
172
+        av_freep(&s->filterbuf[i]);
173
+
174
+    av_freep(&s->data);
175
+    return 0;
176
+}
177
+
166 178
 static av_cold int ape_decode_init(AVCodecContext * avctx)
167 179
 {
168 180
     APEContext *s = avctx->priv_data;
... ...
@@ -195,25 +207,18 @@ static av_cold int ape_decode_init(AVCodecContext * avctx)
195 195
     for (i = 0; i < APE_FILTER_LEVELS; i++) {
196 196
         if (!ape_filter_orders[s->fset][i])
197 197
             break;
198
-        s->filterbuf[i] = av_malloc((ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4);
198
+        FF_ALLOC_OR_GOTO(avctx, s->filterbuf[i],
199
+                         (ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4,
200
+                         filter_alloc_fail);
199 201
     }
200 202
 
201 203
     dsputil_init(&s->dsp, avctx);
202 204
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
203 205
     avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
204 206
     return 0;
205
-}
206
-
207
-static av_cold int ape_decode_close(AVCodecContext * avctx)
208
-{
209
-    APEContext *s = avctx->priv_data;
210
-    int i;
211
-
212
-    for (i = 0; i < APE_FILTER_LEVELS; i++)
213
-        av_freep(&s->filterbuf[i]);
214
-
215
-    av_freep(&s->data);
216
-    return 0;
207
+filter_alloc_fail:
208
+    ape_decode_close(avctx);
209
+    return AVERROR(ENOMEM);
217 210
 }
218 211
 
219 212
 /**