History

fftools/ffmpeg_mux_init: Fix double-free on error

MATCH_PER_STREAM_OPT iterates over all options of a given OptionDef and tests whether they apply to the current stream; if so, they are set to ost->apad, otherwise, the code errors out. If no error happens, ost->apad is av_strdup'ed in order to take ownership of this pointer. But this means that setting it originally was premature, as it leads to double-frees when an error happens lateron. This can simply be reproduced with ffmpeg -filter_complex anullsrc -apad bar -apad:n baz -f null - This is a regression since 83ace80bfd80fcdba2c65fa1d554923ea931d5bd. Fix this by using a temporary variable instead of directly setting ost->apad. Also only strdup the string if it actually is != NULL.

Andreas Rheinhardt committed 2 years ago

Commit ced5c5f1 parent 4a4dcde1 file · +7 −2Browse files

Unified · Split

fftools/ffmpeg_mux_init.c+7−2
@@ -832,6 +832,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 831 unmodified lines
832832 int channels = 0;
833833 char *layout = NULL;
834834 char *sample_fmt = NULL;
835+ const char *apad = NULL;
835836
836837 MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
837838 if (channels) {
@@ -854,8 +855,12 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 16 unmodified lines
854855
855856 MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
856857
857− MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
858− ost->apad = av_strdup(ost->apad);
858+ MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
859+ if (apad) {
860+ ost->apad = av_strdup(apad);
861+ if (!ost->apad)
862+ return AVERROR(ENOMEM);
863+ }
859864 }
860865
861866 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t