[FIX] Fix memory leak in free_sub_track() for blockaddition#2249
[FIX] Fix memory leak in free_sub_track() for blockaddition#2249Shiv0087 wants to merge 1 commit intoCCExtractor:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a memory leak in Matroska/WebVTT subtitle track cleanup by attempting to free sentence->blockaddition and its backing buffer when destroying a subtitle track (related to issue #2247).
Changes:
- Updates
free_sub_track()to free per-sentenceblockadditiondata (and its message buffer) during cleanup. - Adds null checks around the new frees to avoid freeing null pointers.
Comments suppressed due to low confidence (1)
src/lib_ccx/matroska.c:1922
- The
forloop opened at line 1901 is never closed before freeingtrack->sentencesandtrack, sotrack->sentences/trackare freed on the first iteration and the function’s braces become unbalanced (this should also fail to compile). Close theforloop before freeing the track-level allocations, and ensure there is a final}to closefree_sub_track()after the loop/cleanup.
if (track->sentences != NULL)
free(track->sentences);
free(track);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (sentence->blockaddition != NULL) | ||
| { | ||
| /* 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); | ||
| } | ||
| free(sentence->blockaddition); | ||
| } |
There was a problem hiding this comment.
Freeing sentence->blockaddition->cue_settings_list assumes that pointer always equals the start of the allocated message buffer. In parse_segment_cluster_block_group_block_additions(), cue_settings_list is only set when the first item has non-zero length; if it’s empty, the allocated message buffer has no owning pointer and this cleanup will still leak (and you can’t safely free() cue_identifier/comment because they may be offset into the buffer). Consider storing the original message pointer in struct block_addition (e.g., char *raw_message) and freeing that unconditionally, or always retaining message base even when the first field is empty.
|
Closing — the diff has a missing closing brace for the Also, the indentation changed from tabs to spaces and the loop body lost its indentation level entirely. The idea of freeing
|
[FIX] Fix memory leak in free_sub_track() for blockaddition
Summary
Fixes memory leak in
free_sub_track()wheresentence->blockadditionand its associated memorywere not freed.
Fixes #2247
Root Cause
block_additionstructures allocated during parsingwere not released during cleanup, leading to memory leaks
for WebVTT subtitle tracks with BlockAdditions.
Changes
sentence->blockadditionTesting
-- Verified logic via code inspection
In raising this pull request, I confirm the following:
Reason for this PR:
Sanity check:
Repro instructions
Process an
.mkvfile containing WebVTT subtitle tracks with BlockAdditions.Run with a memory analysis tool (e.g., Valgrind) and observe memory leaks
before the fix. After applying the fix, the allocated memory for blockaddition
structures is properly released.