[FIX] Restore free_sub_track scope and keep blockaddition cleanup#2270
[FIX] Restore free_sub_track scope and keep blockaddition cleanup#2270Shiv0087 wants to merge 3 commits intoCCExtractor:masterfrom
Conversation
|
Supersedes #2249 with the requested scope/brace fix, tab indentation cleanup, and retained blockaddition memory cleanup. |
There was a problem hiding this comment.
Pull request overview
Fixes free_sub_track() control-flow/indentation so per-sentence cleanup happens inside the loop while track-level cleanup (free(track->sentences) / free(track)) happens after the loop, and retains the WebVTT blockaddition cleanup added previously.
Changes:
- Restores correct brace scope in
free_sub_track()so track-level frees are not executed per-sentence. - Adds cleanup for
sentence->blockadditionand its backing buffer (cue_settings_list) when present. - Normalizes whitespace/blank lines for readability and consistency.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* cue_settings_list is the base of the message buffer; | ||
| * cue_identifier and comment are pointers into it */ | ||
| if (sentence->blockaddition->cue_settings_list != NULL) | ||
| free(sentence->blockaddition->cue_settings_list); |
There was a problem hiding this comment.
Pull request overview
This PR corrects the control-flow/scope of free_sub_track() in the Matroska subtitle parser and attempts to preserve the WebVTT BlockAddition cleanup that was added in a prior patch.
Changes:
- Restores the intended loop scope in
free_sub_track()so track-level frees happen after the sentence loop. - Adds cleanup for
sentence->blockadditionand its associated buffer pointer (cue_settings_list) when present. - Adjusts formatting/whitespace to match existing file style.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* cue_settings_list is the base of the message buffer; | ||
| * cue_identifier and comment are pointers into it */ | ||
| if (sentence->blockaddition->cue_settings_list != NULL) | ||
| free(sentence->blockaddition->cue_settings_list); | ||
|
|
cfsmp3
left a comment
There was a problem hiding this comment.
The scope/indentation fix is correct — that was the main problem with #2249. But there's a memory leak edge case that Copilot caught and is real.
The issue
parse_segment_cluster_block_group_block_additions() allocates message via read_bytes_signed(). Then cue_settings_list, cue_identifier, and comment are set as pointers INTO that message buffer. But cue_settings_list is only assigned when the first line is non-empty (item_size > 0):
case 0:
if (item_size > 0) // ← only if non-empty
{
newBA->cue_settings_list = message + lastIndex;
...
}If cue settings are absent (empty first line), cue_settings_list stays NULL. Your cleanup code then skips the free:
if (sentence->blockaddition->cue_settings_list != NULL)
free(sentence->blockaddition->cue_settings_list);Result: message buffer leaked.
Fix
Store the message pointer directly in struct block_addition:
// In matroska.h, add to struct block_addition:
char *message_buf; // owning pointer to the backing buffer
// In parse_segment_cluster_block_group_block_additions():
newBA->message_buf = message;
// In free_sub_track():
free(sentence->blockaddition->message_buf); // always frees the backing buffer
free(sentence->blockaddition);This way the owning pointer is always available regardless of whether cue_settings_list was set.
Also: add braces to if (sentence->blockaddition->cue_settings_list != NULL) per our code style.
|
Addressed: added message_buf as owning pointer in struct block_addition, set it in parse_segment_cluster_block_group_block_additions(), and free it in free_sub_track(). This fixes the empty cue-settings leak edge case. |
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 2feb09a...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 2feb09a...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
Summary
This PR fixes the
free_sub_track()cleanup logic after the previous patch introduced a scope/indentation issue.What changed
free_sub_track().sentence->blockaddition->cue_settings_list(when non-NULL)sentence->blockadditionfree(track->sentences)andfree(track)are executed after the sentence loop.Why
The previous diff unintentionally broke loop scope, which moved track-level frees into the wrong context.
This patch preserves the intended memory-leak fix while restoring correct control flow and style.
Related
Validation