Skip to content

Commit 90128d8

Browse files
authored
fix: memory leaks and invalid CSS in WebVTT encoder (#2164)
* fix: memory leaks and invalid CSS in WebVTT encoder - Remove 6 unnecessary strdup() calls on string literals in write_cc_buffer_as_webvtt() — literals are passed directly to write_wrapped() which takes void*, no heap allocation needed. This runs in a per-character inner loop and leaked on every styled subtitle in a broadcast. - Fix invalid CSS: rgba(0, 256, 0, 0.5) -> rgba(0, 255, 0, 0.5) CSS color channels are 0-255; 256 is out of range. - Fix missing free(unescaped) on write-error path in write_stringz_as_webvtt() — matched the existing pattern on the adjacent error path which correctly freed both el and unescaped. Fixes #2154 * fix: move WebVTT changelog entry to unreleased 0.96.7 section
1 parent b2c1bab commit 90128d8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

docs/CHANGES.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.96.7 (unreleased)
22
-------------------
3+
- Fix: Remove strdup() memory leaks in WebVTT styling encoder, fix invalid CSS rgba(0,256,0) green value, fix missing free(unescaped) on write-error path (#2154)
34
- Fix: Prevent crash in Rust timing module when logging out-of-range PTS/FTS timestamps from malformed streams.
45

56
0.96.6 (2026-02-19)

src/lib_ccx/ccx_encoders_webvtt.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static const char *webvtt_inline_css = "\r\nSTYLE\n\n"
9494
" background-color: rgba(255, 255, 255, 0.5);\n"
9595
"}\n"
9696
"::cue(c.bg_green.bg_semi-transparent) {\n"
97-
" background-color: rgba(0, 256, 0, 0.5);\n"
97+
" background-color: rgba(0, 255, 0, 0.5);\n"
9898
"}\n"
9999
"::cue(c.bg_blue.bg_semi-transparent) {\n"
100100
" background-color: rgba(0, 0, 255, 0.5);\n"
@@ -189,6 +189,7 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_
189189
if (written != context->encoded_crlf_length)
190190
{
191191
free(el);
192+
free(unescaped);
192193
return -1;
193194
}
194195
begin += strlen((const char *)begin) + 1;
@@ -502,16 +503,16 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
502503
if (open_font != FONT_REGULAR)
503504
{
504505
if (open_font & FONT_ITALICS)
505-
write_wrapped(context->out->fh, strdup("<i>"), 3);
506+
write_wrapped(context->out->fh, "<i>", 3);
506507
if (open_font & FONT_UNDERLINED)
507-
write_wrapped(context->out->fh, strdup("<u>"), 3);
508+
write_wrapped(context->out->fh, "<u>", 3);
508509
}
509510

510511
// opening events for colors
511512
int open_color = color_events[j] & 0xFF; // Last 16 bytes
512513
if (open_color != COL_WHITE)
513514
{
514-
write_wrapped(context->out->fh, strdup("<c."), 3);
515+
write_wrapped(context->out->fh, "<c.", 3);
515516
write_wrapped(context->out->fh, color_text[open_color][0], strlen(color_text[open_color][0]));
516517
write_wrapped(context->out->fh, ">", 1);
517518
}
@@ -532,17 +533,17 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co
532533
int close_color = color_events[j] >> 16; // First 16 bytes
533534
if (close_color != COL_WHITE)
534535
{
535-
write_wrapped(context->out->fh, strdup("</c>"), 4);
536+
write_wrapped(context->out->fh, "</c>", 4);
536537
}
537538

538539
// closing events for fonts
539540
int close_font = font_events[j] >> 16; // First 16 bytes
540541
if (close_font != FONT_REGULAR)
541542
{
542543
if (close_font & FONT_UNDERLINED)
543-
write_wrapped(context->out->fh, strdup("</u>"), 4);
544+
write_wrapped(context->out->fh, "</u>", 4);
544545
if (close_font & FONT_ITALICS)
545-
write_wrapped(context->out->fh, strdup("</i>"), 4);
546+
write_wrapped(context->out->fh, "</i>", 4);
546547
}
547548
}
548549
}

0 commit comments

Comments
 (0)