Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CEncoderFFmpeg] Fix cleanup of buffer managed by AVIOContext #23185

Merged
merged 1 commit into from
May 19, 2023

Conversation

neo1973
Copy link
Member

@neo1973 neo1973 commented Apr 22, 2023

Description

From the documentation regarding the buffer passed to avio_alloc_context():

Memory block for input/output operations via AVIOContext. The buffer must be allocated with av_malloc() and friends. It may be freed and replaced with a new buffer by libavformat. AVIOContext.buffer holds the buffer currently in use, which must be later freed with av_free().

Motivation and context

Manage memory as described in the documentation.

How has this been tested?

Hasn't been tested!

What is the effect on users?

Unknown, maybe could have caused crashes in the past.

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

From the documentation regarding the buffer passed to avio_alloc_context():

Memory block for input/output operations via AVIOContext. The buffer must be
allocated with av_malloc() and friends. It may be freed and replaced with a new
buffer by libavformat. AVIOContext.buffer holds the buffer currently in use,
which must be later freed with av_free().
@neo1973 neo1973 added Type: Fix non-breaking change which fixes an issue v21 Omega labels Apr 22, 2023
@neo1973 neo1973 added this to the Omega 21.0 Alpha 2 milestone Apr 22, 2023
@@ -60,14 +60,17 @@ bool CEncoderFFmpeg::Init()
if (!m_formatCtx)
throw FFMpegException("Could not allocate output format context");

m_bcBuffer = static_cast<uint8_t*>(av_malloc(BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE));
if (!m_bcBuffer)
auto buffer = static_cast<uint8_t*>(av_malloc(BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

av_mallocz ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation doesn't say that the buffer should be in any particular state so I think a regular av_malloc should be fine.

@neo1973 neo1973 merged commit cce4c61 into xbmc:master May 19, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix non-breaking change which fixes an issue v21 Omega
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants