Fix segfault on recording with old FFmpeg

The AVPacket fields side_data and side_data_elems were not initialized
by av_packet_ref() in old FFmpeg versions (prior to [1]).

As a consequence, on av_packet_unref(), side_data was freed, causing a
segfault.

Fixes <https://github.com/Genymobile/scrcpy/issues/707>

[1]: <http://git.videolan.org/gitweb.cgi/ffmpeg.git/?p=ffmpeg.git;a=commitdiff;h=3b4026e15110547892d5d770b6b43c9e34df458f>
This commit is contained in:
Romain Vimont 2019-08-13 18:49:25 +02:00
parent 20b3f101a4
commit a9c8fa305d

View file

@ -33,6 +33,11 @@ record_packet_new(const AVPacket *packet) {
if (!rec) { if (!rec) {
return NULL; return NULL;
} }
// av_packet_ref() does not initialize all fields in old FFmpeg versions
// See <https://github.com/Genymobile/scrcpy/issues/707>
av_init_packet(&rec->packet);
if (av_packet_ref(&rec->packet, packet)) { if (av_packet_ref(&rec->packet, packet)) {
SDL_free(rec); SDL_free(rec);
return NULL; return NULL;