From b08a98324d35298903098ec8ea9023ecf9515a2f Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 7 Nov 2019 21:58:57 +0100 Subject: [PATCH] Fix segfault on empty file recorded Write the file trailer only if the file header have been written, to avoid a segfault in libav. Fixes . --- app/src/recorder.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/recorder.c b/app/src/recorder.c index f96bcd26..c09e21ae 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -174,9 +174,14 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) { void recorder_close(struct recorder *recorder) { - int ret = av_write_trailer(recorder->ctx); - if (ret < 0) { - LOGE("Failed to write trailer to %s", recorder->filename); + if (recorder->header_written) { + int ret = av_write_trailer(recorder->ctx); + if (ret < 0) { + LOGE("Failed to write trailer to %s", recorder->filename); + recorder->failed = true; + } + } else { + // the recorded file is empty recorder->failed = true; } avio_close(recorder->ctx->pb);