[PR #2011] [MERGED] Fix allocator mismatch in Rust demuxer (use malloc/free instead of Box) #2812

Open
opened 2026-01-29 17:24:02 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/2011
Author: @THE-Amrit-mahto-05
Created: 1/10/2026
Status: Merged
Merged: 1/10/2026
Merged by: @cfsmp3

Base: masterHead: fix/demuxer-allocator-mismatch


📝 Commits (1)

  • a77c21c fix: allocator mismatch in demuxer (use malloc/free instead of Box)

📊 Changes

2 files changed (+55 additions, -21 deletions)

View changed files

📝 src/rust/src/demuxer/common_types.rs (+11 -6)
📝 src/rust/src/libccxr_exports/demuxer.rs (+44 -15)

📄 Description

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

description

In the Rust demuxer, PID_buffers and PIDs_programs were previously allocated using Rust’s Box and sometimes freed in situations where the memory could have been allocated by C. This could cause undefined behavior or crashes when syncing the demuxer state between Rust and C.

This change updates those allocations to C-style (malloc/calloc) and frees them using free, ensuring that Rust and C memory management are fully compatible.

  • Allocations for PSIBuffer and PMTEntry now use malloc/calloc.
  • Deallocation uses free everywhere: in the Drop implementation for CcxDemuxer and in Rust ↔ C synchronization functions.
  • No other logic in the demuxer has been changed—only memory management.

Why

The demuxer’s synchronization logic could previously free pointers incorrectly, leading to crashes during repeated demuxer state updates or in multi-threaded scenarios. Using C-compatible allocation ensures safe interoperability between Rust and C.

Testing

  • Verified that buffers and PMT entries are correctly allocated and freed.
  • Repeated Rust ↔ C synchronization does not leak memory or crash.
  • Runs safely under normal usage and stress tests.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/2011 **Author:** [@THE-Amrit-mahto-05](https://github.com/THE-Amrit-mahto-05) **Created:** 1/10/2026 **Status:** ✅ Merged **Merged:** 1/10/2026 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/demuxer-allocator-mismatch` --- ### 📝 Commits (1) - [`a77c21c`](https://github.com/CCExtractor/ccextractor/commit/a77c21c06c434afc33940e5cb44419503be77f57) fix: allocator mismatch in demuxer (use malloc/free instead of Box) ### 📊 Changes **2 files changed** (+55 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `src/rust/src/demuxer/common_types.rs` (+11 -6) 📝 `src/rust/src/libccxr_exports/demuxer.rs` (+44 -15) </details> ### 📄 Description <!-- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. --> **In raising this pull request, I confirm the following (please check boxes):** - [x] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [x] I have checked that another pull request for this purpose does not exist. - [x] I have considered, and confirmed that this submission will be valuable to others. - [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [x] I give this submission freely, and claim no ownership to its content. - [x] **I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT).** **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [ ] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [x] I am an active contributor to CCExtractor. --- ### description In the Rust demuxer, PID_buffers and PIDs_programs were previously allocated using Rust’s Box and sometimes freed in situations where the memory could have been allocated by C. This could cause undefined behavior or crashes when syncing the demuxer state between Rust and C. This change updates those allocations to C-style (malloc/calloc) and frees them using free, ensuring that Rust and C memory management are fully compatible. - Allocations for PSIBuffer and PMTEntry now use malloc/calloc. - Deallocation uses free everywhere: in the Drop implementation for CcxDemuxer and in Rust ↔ C synchronization functions. - No other logic in the demuxer has been changed—only memory management. ### Why The demuxer’s synchronization logic could previously free pointers incorrectly, leading to crashes during repeated demuxer state updates or in multi-threaded scenarios. Using C-compatible allocation ensures safe interoperability between Rust and C. ### Testing - Verified that buffers and PMT entries are correctly allocated and freed. - Repeated Rust ↔ C synchronization does not leak memory or crash. - Runs safely under normal usage and stress tests. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:24:02 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2812