Validate that a hw_frames_ctx is available before using it for the AVHWAccel.free_frame_priv callback, and don't require it to be present when the callback is not in use by the HWAccel. v2: check for free_frame_priv (Hendrik) v3: return EINVAL (Christoph Reiter) v4: better commit message (Hendrik) v5: fix typo with missed frames_ctx (Lynne) See[1]: https://github.com/msys2/MINGW-packages/pull/19050 Fixes: be07145109 ("avcodec: add AVHWAccel.free_frame_priv callback") CC: Lynne <dev@lynne.ee> CC: Christoph Reiter <reiter.christoph@gmail.com> Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -1838,17 +1838,26 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) · 1837 unmodified lines | ||
| 1838 | 1838 | int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private) |
| 1839 | 1839 | { |
| 1840 | 1840 | const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); |
| 1841 | − AVHWFramesContext *frames_ctx; | |
| 1842 | 1841 | |
| 1843 | 1842 | if (!hwaccel || !hwaccel->frame_priv_data_size) |
| 1844 | 1843 | return 0; |
| 1845 | 1844 | |
| 1846 | 1845 | av_assert0(!*hwaccel_picture_private); |
| 1847 | 1846 | |
| 1848 | − frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; | |
| 1849 | − *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, | |
| 1850 | − frames_ctx->device_ctx, | |
| 1851 | − hwaccel->free_frame_priv); | |
| 1847 | + if (hwaccel->free_frame_priv) { | |
| 1848 | + AVHWFramesContext *frames_ctx; | |
| 1849 | + | |
| 1850 | + if (!avctx->hw_frames_ctx) | |
| 1851 | + return AVERROR(EINVAL); | |
| 1852 | + | |
| 1853 | + frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data; | |
| 1854 | + *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, | |
| 1855 | + frames_ctx->device_ctx, | |
| 1856 | + hwaccel->free_frame_priv); | |
| 1857 | + } else { | |
| 1858 | + *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size); | |
| 1859 | + } | |
| 1860 | + | |
| 1852 | 1861 | if (!*hwaccel_picture_private) |
| 1853 | 1862 | return AVERROR(ENOMEM); |
| 1854 | 1863 | |