Skip to content

Commit

Permalink
Fix segfault on empty file recorded
Browse files Browse the repository at this point in the history
Write the file trailer only if the file header have been written, to
avoid a segfault in libav.

Fixes <#918>.
  • Loading branch information
rom1v committed Nov 7, 2019
1 parent c916af0 commit b08a983
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/src/recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b08a983

Please sign in to comment.