Ensure all hwaccels that allocate a buffer use NVDECContext->bitstream_internal instead. Otherwise, if FFHWAccel->end_frame() isn't called before FFHWAccel->uninit(), an attempt to free a stale pointer to memory not owned by the hwaccel could take place.
Unified · Split
| @@ -259,8 +259,8 @@ int ff_nvdec_decode_uninit(AVCodecContext *avctx) · 258 unmodified lines | |||
| 259 | { | 259 | { |
| 260 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; | 260 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; |
| 261 | 261 | ||
| 262 | av_freep(&ctx->bitstream); | ||
| 263 | av_freep(&ctx->bitstream_internal); | 262 | av_freep(&ctx->bitstream_internal); |
| 263 | ctx->bitstream = NULL; | ||
| 264 | ctx->bitstream_len = 0; | 264 | ctx->bitstream_len = 0; |
| 265 | ctx->bitstream_allocated = 0; | 265 | ctx->bitstream_allocated = 0; |
| 266 | 266 | ||
| @@ -138,11 +138,11 @@ static int nvdec_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, · 137 unmodified lines | |||
| 138 | const H264SliceContext *sl = &h->slice_ctx[0]; | 138 | const H264SliceContext *sl = &h->slice_ctx[0]; |
| 139 | void *tmp; | 139 | void *tmp; |
| 140 | 140 | ||
| 141 | tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated, | 141 | tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated, |
| 142 | ctx->bitstream_len + size + 3); | 142 | ctx->bitstream_len + size + 3); |
| 143 | if (!tmp) | 143 | if (!tmp) |
| 144 | return AVERROR(ENOMEM); | 144 | return AVERROR(ENOMEM); |
| 145 | ctx->bitstream = tmp; | 145 | ctx->bitstream = ctx->bitstream_internal = tmp; |
| 146 | 146 | ||
| 147 | tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, | 147 | tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, |
| 148 | (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); | 148 | (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); |
| @@ -274,11 +274,11 @@ static int nvdec_hevc_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, · 273 unmodified lines | |||
| 274 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; | 274 | NVDECContext *ctx = avctx->internal->hwaccel_priv_data; |
| 275 | void *tmp; | 275 | void *tmp; |
| 276 | 276 | ||
| 277 | tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated, | 277 | tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated, |
| 278 | ctx->bitstream_len + size + 3); | 278 | ctx->bitstream_len + size + 3); |
| 279 | if (!tmp) | 279 | if (!tmp) |
| 280 | return AVERROR(ENOMEM); | 280 | return AVERROR(ENOMEM); |
| 281 | ctx->bitstream = tmp; | 281 | ctx->bitstream = ctx->bitstream_internal = tmp; |
| 282 | 282 | ||
| 283 | tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, | 283 | tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, |
| 284 | (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); | 284 | (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); |