[FFmpeg-devel] [PATCH 4/6] avformat/flvenc: Add deinit function

Michael Niedermayer michael at niedermayer.cc
Thu Oct 24 20:36:38 EEST 2019


On Wed, Oct 23, 2019 at 02:59:42PM +0200, Andreas Rheinhardt wrote:
> Fixes memleaks when the trailer is never written or when shift_data()
> fails when writing the trailer.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavformat/flvenc.c | 30 ++++++++++++++++--------------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
> index fb1dede7ae..0da54f3365 100644
> --- a/libavformat/flvenc.c
> +++ b/libavformat/flvenc.c
> @@ -784,7 +784,7 @@ static int flv_write_trailer(AVFormatContext *s)
>      int64_t cur_pos = avio_tell(s->pb);
>  
>      if (build_keyframes_idx) {
> -        FLVFileposition *newflv_posinfo, *p;
> +        FLVFileposition *newflv_posinfo;
>  
>          avio_seek(pb, flv->videosize_offset, SEEK_SET);
>          put_amf_double(pb, flv->videosize);
> @@ -819,19 +819,6 @@ static int flv_write_trailer(AVFormatContext *s)
>              put_amf_double(pb, newflv_posinfo->keyframe_timestamp);
>          }
>  
> -        newflv_posinfo = flv->head_filepositions;
> -        while (newflv_posinfo) {
> -            p = newflv_posinfo->next;
> -            if (p) {
> -                newflv_posinfo->next = p->next;
> -                av_free(p);
> -                p = NULL;
> -            } else {
> -                av_free(newflv_posinfo);
> -                newflv_posinfo = NULL;
> -            }
> -        }
> -
>          put_amf_string(pb, "");
>          avio_w8(pb, AMF_END_OF_OBJECT);
>  
> @@ -1093,6 +1080,20 @@ static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
>      return ret;
>  }
>  
> +static void flv_deinit(AVFormatContext *s)
> +{
> +    FLVContext *flv = s->priv_data;
> +    FLVFileposition *filepos = flv->head_filepositions;
> +
> +    while (filepos) {
> +        FLVFileposition *next = filepos->next;
> +        av_free(filepos);
> +        filepos = next;
> +    }
> +    flv->filepositions = flv->head_filepositions = NULL;
> +    flv->filepositions_count = 0;
> +}
> +
>  static const AVOption options[] = {
>      { "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
>      { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },

Am i missing something or would this be simpler and more efficient
as an array ?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191024/d629b23b/attachment.sig>


More information about the ffmpeg-devel mailing list