mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-04-25 07:29:54 +00:00
[PR #1840] [MERGED] fix(memory): Fix uninitialized memory and memory leaks found by Valgrind #2598
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/CCExtractor/ccextractor/pull/1840
Author: @cfsmp3
Created: 12/17/2025
Status: ✅ Merged
Merged: 12/18/2025
Merged by: @cfsmp3
Base:
master← Head:fix/valgrind-memory-issues📝 Commits (9)
89849d3fix(memory): Fix uninitialized memory and memory leaks found by Valgrind683468efix(memory): Fix use-after-free and memory leaks in Rust FFI3d5d8e2fix(memory): Fix major memory leaks in Rust FFI demuxer and decoder7b1a169fix(memory): Fix use-after-free in Teletext and uninitialized variables627e085fix(memory): Fix 608 decoder memory leak in dec_sub.data4a30434fix(memory): Fix XDS memory leaks in encoder and decoder cleanupd72646afix(memory): Fix XDS memory leak in rcwt_loop path4429067fix(rust): Fix Drop compatibility and formatting issues859741afix(rust): Remove unused import free_rust_c_string_array📊 Changes
15 files changed (+302 additions, -64 deletions)
View changed files
📝
src/lib_ccx/ccx_decoders_common.c(+25 -0)📝
src/lib_ccx/ccx_decoders_xds.c(+2 -0)📝
src/lib_ccx/ccx_demuxer.c(+1 -1)📝
src/lib_ccx/ccx_encoders_common.c(+5 -0)📝
src/lib_ccx/ccx_encoders_spupng.c(+1 -3)📝
src/lib_ccx/general_loop.c(+33 -22)📝
src/lib_ccx/lib_ccx.c(+2 -1)📝
src/lib_ccx/telxcc.c(+3 -1)📝
src/lib_ccx/ts_info.c(+15 -0)📝
src/rust/src/common.rs(+74 -18)📝
src/rust/src/decoder/mod.rs(+7 -4)📝
src/rust/src/demuxer/common_types.rs(+28 -0)📝
src/rust/src/demuxer/demux.rs(+42 -6)📝
src/rust/src/libccxr_exports/demuxer.rs(+19 -8)📝
src/rust/src/utils.rs(+45 -0)📄 Description
Summary
Comprehensive memory fixes found via Valgrind testing. This PR eliminates memory leaks, use-after-free bugs, and uninitialized memory issues across both C and Rust code.
Commits
calloc()instead ofmalloc()in demuxer/decoder initcopy_from_rust()is called multiple timesdec_ctx->private_dataafter Teletext context is freeddinit_cc_decode()xds_strwhen skipping invalid timestamps--in=binand--in=rawformatsValgrind Test Results (245 tests)
All tested ranges show 0 bytes definitely lost.
Key Fixes Verified
Technical Details
C Code Fixes
ccx_demuxer.c:calloc()ininit_demuxer()lib_ccx.c:calloc()ininit_decoder_setting()telxcc.c:calloc()intelxcc_init()general_loop.c: Initialize variables, add rcwt_loop cleanupccx_decoders_common.c: Free DVB bitmap and XDS strings in cleanupccx_encoders_common.c: Free XDS strings on invalid timestamp skipRust FFI Fixes
utils.rs: Addreplace_rust_c_string(),free_rust_c_string_array()common.rs: Only set inputfile/enc_cfg on first call to prevent leaksdemuxer.rs: Direct C struct manipulation inccxr_demuxer_close()decoder/mod.rs: Only allocate encoder whenctx.encoderis nullcommon_types.rs: AddDropforCcxDemuxerto free FFI allocationsKnown Pre-existing Issues
--datapid(complex interaction, pre-existing)Test plan
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.