Skip to content

Commit 1cb57d3

Browse files
committed
video_display: fix use ptr after free
video_display putf implementation may free the frame so that the pointer is no longer valid upon the exit from the callback (or anytime later). This is the case for eg. vdisp/decklink. Fixes `uv -t testcard -c lavc -d dummy:discard` (wrong color in output line): ``` [dummy] 126 frames in 5.03501 seconds = 25.0248 FPS ``` even though FPS is +/- the nominal 25. Depending on circumstances it could have also easily crashed (access after free).
1 parent 0349beb commit 1cb57d3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/video_display.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ static bool display_frame_helper(struct display *d, struct video_frame *frame, l
351351
MIN_FPS_PERC_WARN = 98,
352352
MIN_FPS_PERC_WARN2 = 90,
353353
};
354+
const double frame_fps = frame->fps;
354355
bool ret = d->funcs->putf(d->state, frame, timeout_ns);
355356
if (!d->funcs->generic_fps_indicator_prefix) {
356357
return ret;
@@ -364,7 +365,7 @@ static bool display_frame_helper(struct display *d, struct video_frame *frame, l
364365
if (seconds_ns > 5 * NS_IN_SEC) {
365366
const double seconds = (double) seconds_ns / NS_IN_SEC;
366367
const double fps = d->frames / seconds;
367-
const char *const fps_col = get_stat_color(fps / frame->fps);
368+
const char *const fps_col = get_stat_color(fps / frame_fps);
368369

369370
log_msg(LOG_LEVEL_INFO,
370371
TERM_BOLD TERM_FG_MAGENTA

0 commit comments

Comments
 (0)