mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
examples/muxing: fix memory leak.
Do not re-call avcodec_get_context_defaults3(), it is already called by avformat_new_stream() and it leaks the codec priv_data that was already allocated. Use avformat_free_context() instead of freeing (not) everything manually. Fix trac ticket #2322.
This commit is contained in:
parent
ad48556135
commit
9b211c43dc
@ -86,7 +86,6 @@ static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
avcodec_get_context_defaults3(c, *codec);
|
|
||||||
c->codec_id = codec_id;
|
c->codec_id = codec_id;
|
||||||
|
|
||||||
c->bit_rate = 400000;
|
c->bit_rate = 400000;
|
||||||
@ -396,7 +395,7 @@ int main(int argc, char **argv)
|
|||||||
AVStream *audio_st, *video_st;
|
AVStream *audio_st, *video_st;
|
||||||
AVCodec *audio_codec, *video_codec;
|
AVCodec *audio_codec, *video_codec;
|
||||||
double audio_pts, video_pts;
|
double audio_pts, video_pts;
|
||||||
int ret, i;
|
int ret;
|
||||||
|
|
||||||
/* Initialize libavcodec, and register all codecs and formats. */
|
/* Initialize libavcodec, and register all codecs and formats. */
|
||||||
av_register_all();
|
av_register_all();
|
||||||
@ -504,18 +503,12 @@ int main(int argc, char **argv)
|
|||||||
if (audio_st)
|
if (audio_st)
|
||||||
close_audio(oc, audio_st);
|
close_audio(oc, audio_st);
|
||||||
|
|
||||||
/* Free the streams. */
|
|
||||||
for (i = 0; i < oc->nb_streams; i++) {
|
|
||||||
av_freep(&oc->streams[i]->codec);
|
|
||||||
av_freep(&oc->streams[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(fmt->flags & AVFMT_NOFILE))
|
if (!(fmt->flags & AVFMT_NOFILE))
|
||||||
/* Close the output file. */
|
/* Close the output file. */
|
||||||
avio_close(oc->pb);
|
avio_close(oc->pb);
|
||||||
|
|
||||||
/* free the stream */
|
/* free the stream */
|
||||||
av_free(oc);
|
avformat_free_context(oc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user