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
259259 {
260260 NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
261261
262− av_freep(&ctx->bitstream);
263262 av_freep(&ctx->bitstream_internal);
263+ ctx->bitstream = NULL;
264264 ctx->bitstream_len = 0;
265265 ctx->bitstream_allocated = 0;
266266
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
138138 const H264SliceContext *sl = &h->slice_ctx[0];
139139 void *tmp;
140140
141− tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated,
141+ tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
142142 ctx->bitstream_len + size + 3);
143143 if (!tmp)
144144 return AVERROR(ENOMEM);
145− ctx->bitstream = tmp;
145+ ctx->bitstream = ctx->bitstream_internal = tmp;
146146
147147 tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
148148 (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
274274 NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
275275 void *tmp;
276276
277− tmp = av_fast_realloc(ctx->bitstream, &ctx->bitstream_allocated,
277+ tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
278278 ctx->bitstream_len + size + 3);
279279 if (!tmp)
280280 return AVERROR(ENOMEM);
281− ctx->bitstream = tmp;
281+ ctx->bitstream = ctx->bitstream_internal = tmp;
282282
283283 tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
284284 (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