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 <https://github.com/Genymobile/scrcpy/issues/918>.
This commit is contained in:
parent
c916af0984
commit
b08a98324d
1 changed files with 8 additions and 3 deletions
|
@ -174,11 +174,16 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
|||
|
||||
void
|
||||
recorder_close(struct recorder *recorder) {
|
||||
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);
|
||||
avformat_free_context(recorder->ctx);
|
||||
|
||||
|
|
Loading…
Reference in a new issue