Skip to content

fix(ffmpeg/vulkan): destroy leaked VkImageViews during encoder uninit#728

Merged
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
neatnoise:fix-vulkan-imageview-leak
Jul 13, 2026
Merged

fix(ffmpeg/vulkan): destroy leaked VkImageViews during encoder uninit#728
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
neatnoise:fix-vulkan-imageview-leak

Conversation

@neatnoise

Copy link
Copy Markdown
Contributor

Description

ff_hw_base_encode_close() frees remaining pictures via base_encode_pic_free() without calling the encoder-specific .free callback, leaking their VkImageViews. Also moves av_buffer_pool_uninit before base close so Vulkan packet buffers can be properly destroyed while the device reference is still valid.

This addresses the 2 leaked VkImageViews reported via validation layers in LizardByte/Sunshine#5360 (comment).

Complements #727 (CBS context leak fix).

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@Kishi85

Kishi85 commented Jul 13, 2026

Copy link
Copy Markdown

This combined with #727 seems to fix the vulkan encoder memory leak in Sunshine.

Combined fix for two Vulkan encoder leaks:

1. CBS context: encoders never called ff_cbs_close(&enc->cbs),
   leaking cloned SPS/VPS/PPS structs (~1-8 MB per session).

2. VkImageView: ff_hw_base_encode_close() frees pictures without
   calling .free callback, leaking VkImageViews. Also reorders
   av_buffer_pool_uninit before base close.
@neatnoise
neatnoise force-pushed the fix-vulkan-imageview-leak branch from 9561a75 to 393d064 Compare July 13, 2026 11:30
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit 22f2da9 into LizardByte:master Jul 13, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants