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:
Romain Vimont 2019-11-07 21:58:57 +01:00
parent c916af0984
commit b08a98324d

View file

@ -174,9 +174,14 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
void void
recorder_close(struct recorder *recorder) { recorder_close(struct recorder *recorder) {
int ret = av_write_trailer(recorder->ctx); if (recorder->header_written) {
if (ret < 0) { int ret = av_write_trailer(recorder->ctx);
LOGE("Failed to write trailer to %s", recorder->filename); if (ret < 0) {
LOGE("Failed to write trailer to %s", recorder->filename);
recorder->failed = true;
}
} else {
// the recorded file is empty
recorder->failed = true; recorder->failed = true;
} }
avio_close(recorder->ctx->pb); avio_close(recorder->ctx->pb);