[PR #1994] Free filebuffer to prevent 16MB memory leak in ccxr_demuxer_close #2795

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

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1994
Author: @THE-Amrit-mahto-05
Created: 1/7/2026
Status: 🔄 Open

Base: masterHead: fix/demuxer-memory-leak


📝 Commits (3)

  • e1ba42c fix: Free filebuffer to prevent 16MB memory leak in ccxr_demuxer_close
  • 472c8bd fix Free Rust filebuffer in ccxr_demuxer_delete to prevent memory leak and UB
  • 70d325f re run checks

📊 Changes

2 files changed (+35 additions, -0 deletions)

View changed files

📝 src/lib_ccx/ccx_demuxer.c (+14 -0)
📝 src/rust/src/libccxr_exports/demuxer.rs (+21 -0)

📄 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

fixes a critical memory leak in CCExtractor where the file buffer allocated for each demuxer instance is never freed, causing 16MB of memory to leak per instance. This occurs because Rust allocated the buffer and then "forgot" it so C code could use it, leaving it unmanaged.

Changes made

  • In ccxr_demuxer_close, the raw file buffer pointer is reclaimed as a boxed slice and dropped to allow Rust to free the memory.
  • The pointer is then set to NULL to prevent double-free issues if C code tries to clean it up.
  • Updated comments to explain why this step is necessary.

Fixes: #1993

Verification

  • Verified with multiple demuxer instances that memory usage no longer grows by 16MB per instance.
  • Ensured normal demuxer functionality is unaffected.

🔄 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/1994 **Author:** [@THE-Amrit-mahto-05](https://github.com/THE-Amrit-mahto-05) **Created:** 1/7/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/demuxer-memory-leak` --- ### 📝 Commits (3) - [`e1ba42c`](https://github.com/CCExtractor/ccextractor/commit/e1ba42c4713efe23d6717f393df9a6572972af7a) fix: Free filebuffer to prevent 16MB memory leak in ccxr_demuxer_close - [`472c8bd`](https://github.com/CCExtractor/ccextractor/commit/472c8bd3cd88140bb9905d0e194ec15f957a28a7) fix Free Rust filebuffer in ccxr_demuxer_delete to prevent memory leak and UB - [`70d325f`](https://github.com/CCExtractor/ccextractor/commit/70d325f55808714c8f7daa2674a68c24af6058db) re run checks ### 📊 Changes **2 files changed** (+35 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/ccx_demuxer.c` (+14 -0) 📝 `src/rust/src/libccxr_exports/demuxer.rs` (+21 -0) </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 fixes a critical memory leak in CCExtractor where the file buffer allocated for each demuxer instance is never freed, causing 16MB of memory to leak per instance. This occurs because Rust allocated the buffer and then "forgot" it so C code could use it, leaving it unmanaged. ### Changes made - In `ccxr_demuxer_close`, the raw file buffer pointer is reclaimed as a boxed slice and dropped to allow Rust to free the memory. - The pointer is then set to `NULL` to prevent double-free issues if C code tries to clean it up. - Updated comments to explain why this step is necessary. Fixes: #1993 ### Verification - Verified with multiple demuxer instances that memory usage no longer grows by 16MB per instance. - Ensured normal demuxer functionality is unaffected. --- <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:23:56 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2795