Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/lib_ccx/matroska.c
Original file line number Diff line number Diff line change
Expand Up @@ -1898,12 +1898,24 @@ void free_sub_track(struct matroska_sub_track *track)
free(track->lang_ietf);
if (track->codec_id_string != NULL)
free(track->codec_id_string);
for (int i = 0; i < track->sentence_count; i++)
{
struct matroska_sub_sentence *sentence = track->sentences[i];
free(sentence->text);
free(sentence);
}
for (int i = 0; i < track->sentence_count; i++)
{
struct matroska_sub_sentence *sentence = track->sentences[i];

free(sentence->text);

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);
}
Comment on lines +1907 to +1916
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
free(sentence);

if (track->sentences != NULL)
free(track->sentences);
free(track);
Expand Down
Loading