History

avcodec/nvdec: don't free NVDECContext->bitstream

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.

James Almer committed 2 years ago

Commit 7f920141 parent bd3e71b3 files · +5 −5Browse files

Unified · Split

3 files
  1. libavcodec/nvdec.c +1 −1
  2. libavcodec/nvdec_h264.c +2 −2
  3. libavcodec/nvdec_hevc.c +2 −2
libavcodec/nvdec.c+1−1
@@ -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
libavcodec/nvdec_h264.c+2−2
@@ -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));
libavcodec/nvdec_hevc.c+2−2
@@ -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));

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