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.
Unified · Split
| @@ -832,6 +832,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 831 unmodified lines | ||
| 832 | 832 | int channels = 0; |
| 833 | 833 | char *layout = NULL; |
| 834 | 834 | char *sample_fmt = NULL; |
| 835 | + const char *apad = NULL; | |
| 835 | 836 | |
| 836 | 837 | MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st); |
| 837 | 838 | if (channels) { |
| @@ -854,8 +855,12 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 16 unmodified lines | ||
| 854 | 855 | |
| 855 | 856 | MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st); |
| 856 | 857 | |
| 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 | + } | |
| 859 | 864 | } |
| 860 | 865 | |
| 861 | 866 | return 0; |