#2937(avformat:new): avformat_new_stream() memory leak
#2937: avformat_new_stream() memory leak -------------------------------------+------------------------------------- Reporter: jlsantiago0 | Type: defect Status: new | Priority: important Component: avformat | Version: git- Keywords: memory leak | master Blocking: | Blocked By: Analyzed by developer: 0 | Reproduced by developer: 0 -------------------------------------+------------------------------------- avformat_new_stream() calls avcodec_alloc_context3() which can allocate data that is not free'd by the manual freeing of the codec context done by ff_free_stream() which is called by avformat_free_context(). In particular the st->codec->priv_data is allocated, but not free'd. The attached patch modifies ff_free_stream() to call avcodec_close() to properly close the codec context allocated in avformat_new_stream() . For instance in the following code: {{{ AVFormatContext * formatCtx; AVCodec * codec; AVStream * avStream; AVOutputFormat * outputFormat; const char * shortName = "mpegts"; const char * outputURL = "file://somefile.ts"; outputFormat = av_guess_format(shortName, outputURL, NULL); assert(outputFormat != NULL); avformat_alloc_output_context2(&formatCtx, outputFormat, shortName, outputURL); assert(formatCtx != NULL); avio_open2(&formatCtx->pb, outputURL, AVIO_FLAG_WRITE, NULL, NULL); codec = avcodec_find_decoder(AV_CODEC_ID_H264); assert(codec != NULL); avStream = avformat_new_stream(formatCtx, codec); assert(avStream != NULL); avformat_write_header(formatCtx, NULL); av_write_trailer(formatCtx); avio_close(formatCtx->pb); formatCtx->pb = NULL; # Not all of the st[]->codec is free'd here. avformat_free_context(formatCtx); }}} -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2937> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker
#2937: avformat_new_stream() memory leak -------------------------------------+------------------------------------ Reporter: jlsantiago0 | Owner: Type: defect | Status: new Priority: normal | Component: avformat Version: git-master | Resolution: Keywords: leak | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+------------------------------------ Changes (by cehoyos): * keywords: memory leak => leak * priority: important => normal Comment: Please send patches to the ffmpeg-devel mailing list where they will be reviewed. (If you believe that this is not clearly explained on the ''New Ticket'' page, please tell us!) -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2937#comment:1> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker
#2937: avformat_new_stream() memory leak -------------------------------------+------------------------------------ Reporter: jlsantiago0 | Owner: Type: defect | Status: new Priority: normal | Component: avformat Version: git-master | Resolution: Keywords: leak | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+------------------------------------ Comment (by jlsantiago0): OK. I sent the patch and the description to the ffmpeg-devel list. -- Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2937#comment:2> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker
#2937: avformat_new_stream() memory leak -------------------------------------+------------------------------------ Reporter: jlsantiago0 | Owner: Type: defect | Status: new Priority: normal | Component: avformat Version: git-master | Resolution: Keywords: leak | Blocked By: Blocking: | Reproduced by developer: 0 Analyzed by developer: 0 | -------------------------------------+------------------------------------ Comment (by cehoyos): http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/167998 -- Ticket URL: <https://trac.ffmpeg.org/ticket/2937#comment:3> FFmpeg <http://ffmpeg.org> FFmpeg issue tracker
participants (1)
-
FFmpeg