fix: remove double free in multiprogram encoder initialization (Debug build)#2147
Open
Atul-Chahar wants to merge 2 commits intoCCExtractor:masterfrom
Open
fix: remove double free in multiprogram encoder initialization (Debug build)#2147Atul-Chahar wants to merge 2 commits intoCCExtractor:masterfrom
Atul-Chahar wants to merge 2 commits intoCCExtractor:masterfrom
Conversation
The print_scc_time() function was using a hardcoded 29.97 FPS value to compute frame numbers, ignoring the dynamically-updated current_fps global. This caused incorrect SCC timecodes for any non-NTSC source (24fps, 25fps, 30fps, 50/60fps). Now uses current_fps which is updated at runtime from stream NAL data or framerates_values[], ensuring correct frame numbers for all sources. Fixes CCExtractor#2145
In update_encoder_list_cinfo(), the output_filename was being freed immediately after passing it to init_encoder(). However, the encoder stores this pointer and later frees it during dinit_encoder() -> dinit_output_ctx() -> dinit_write() -> freep(&wb->filename). This caused a double-free error that only appeared in Debug builds which have additional heap validation, explaining why the bug only showed in Debug builds on Windows (issue CCExtractor#2126). The fix removes the premature free since the encoder now owns the memory and will clean it up properly during its lifecycle.
Collaborator
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 733ed89...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
Collaborator
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 733ed89...:
Congratulations: Merging this PR would fix the following tests:
All tests passed completely. Check the result page for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2126 - Debug build error message on Windows
Root Cause
In update_encoder_list_cinfo() (src/lib_ccx/lib_ccx.c), the output_filename was being freed immediately after passing it to init_encoder():
c enc_ctx = init_encoder(&ccx_options.enc_cfg); list_add_tail(&(enc_ctx->list), &(ctx->enc_ctx_head)); freep(&ccx_options.enc_cfg.output_filename); // BUG: premature free!However, the encoder stores this pointer and later frees it during cleanup:
This caused a double-free error that only appeared in Debug builds (which have additional heap validation), explaining why the bug only showed in Debug builds on Windows.
Fix
Remove the premature free (line 479) since the encoder now owns the memory and will clean it up properly during its lifecycle.
Testing
This fix removes the problematic line. The encoder already properly manages the memory throughout its lifecycle, so no other changes are needed.