Skip to content

fix: remove double free in multiprogram encoder initialization (Debug build)#2147

Open
Atul-Chahar wants to merge 2 commits intoCCExtractor:masterfrom
Atul-Chahar:fix/debug-build-double-free
Open

fix: remove double free in multiprogram encoder initialization (Debug build)#2147
Atul-Chahar wants to merge 2 commits intoCCExtractor:masterfrom
Atul-Chahar:fix/debug-build-double-free

Conversation

@Atul-Chahar
Copy link
Contributor

@Atul-Chahar Atul-Chahar commented Feb 26, 2026

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:

  • dinit_encoder() → dinit_output_ctx() → dinit_write() → reep(&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.

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.


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.
@ccextractor-bot
Copy link
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...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 34/34

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

All tests passed completely.

Check the result page for more info.

@ccextractor-bot
Copy link
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...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 34/34

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

All tests passed completely.

Check the result page for more info.

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.

[Bug] CCExtractor 0.96 x64 Debug build displays error message at end of runs on Windows 11 PC

2 participants