When decoding non-keyframes, the decoding process expects there to be two reference frames, the last one and the golden one. The existence of the golden one is checked and in case it is there, it is presumed that the last one exists as well. This assumption is wrong in case of memory allocation failure, namely in case the call to ff_thread_ref_frame() that sets the last frame fails. Fix this by actually performing a shuffle without creating new references. This can't fail and has the advantage of fewer implicit allocations.
Unified · Split
| @@ -2498,19 +2498,14 @@ static int update_frames(AVCodecContext *avctx) · 2497 unmodified lines | |||
| 2498 | Vp3DecodeContext *s = avctx->priv_data; | 2498 | Vp3DecodeContext *s = avctx->priv_data; |
| 2499 | int ret = 0; | 2499 | int ret = 0; |
| 2500 | 2500 | ||
| 2501 | /* shuffle frames (last = current) */ | ||
| 2502 | ff_thread_release_ext_buffer(avctx, &s->last_frame); | ||
| 2503 | ret = ff_thread_ref_frame(&s->last_frame, &s->current_frame); | ||
| 2504 | if (ret < 0) | ||
| 2505 | goto fail; | ||
| 2506 | |||
| 2507 | if (s->keyframe) { | 2501 | if (s->keyframe) { |
| 2508 | ff_thread_release_ext_buffer(avctx, &s->golden_frame); | 2502 | ff_thread_release_ext_buffer(avctx, &s->golden_frame); |
| 2509 | ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame); | 2503 | ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame); |
| 2510 | } | 2504 | } |
| 2505 | /* shuffle frames */ | ||
| 2506 | ff_thread_release_ext_buffer(avctx, &s->last_frame); | ||
| 2507 | FFSWAP(ThreadFrame, s->last_frame, s->current_frame); | ||
| 2511 | 2508 | ||
| 2512 | fail: | ||
| 2513 | ff_thread_release_ext_buffer(avctx, &s->current_frame); | ||
| 2514 | return ret; | 2509 | return ret; |
| 2515 | } | 2510 | } |
| 2516 | 2511 | ||