mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 21:00:41 +08:00
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 since83ace80bfd. Fix this by using a temporary variable instead of directly setting ost->apad. Also only strdup the string if it actually is != NULL. Reviewed-by: Marth64 <marth64@proxyid.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> (cherry picked from commitced5c5fdb8) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
8e96472d7c
commit
e3b8e3e071
@@ -845,6 +845,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
|
||||
int channels = 0;
|
||||
char *layout = NULL;
|
||||
char *sample_fmt = NULL;
|
||||
const char *apad = NULL;
|
||||
|
||||
MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
|
||||
if (channels) {
|
||||
@@ -882,8 +883,12 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
|
||||
|
||||
MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
|
||||
|
||||
MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
|
||||
ost->apad = av_strdup(ost->apad);
|
||||
MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
|
||||
if (apad) {
|
||||
ost->apad = av_strdup(apad);
|
||||
if (!ost->apad)
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
#if FFMPEG_OPT_MAP_CHANNEL
|
||||
/* check for channel mapping for this audio stream */
|
||||
|
||||
Reference in New Issue
Block a user