diff mbox

[FFmpeg-devel,2/2] avformat/avienc: add deinit function

Message ID 20191019141108.1434-2-jamrial@gmail.com
State Accepted
Commit a581bb66ea5eb981e2e498ca301df7d1ef15a6a3
Headers show

Commit Message

James Almer Oct. 19, 2019, 2:11 p.m. UTC
Fixes ticket #8302

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/avienc.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Paul B Mahol Oct. 19, 2019, 2:18 p.m. UTC | #1
LGTM

On 10/19/19, James Almer <jamrial@gmail.com> wrote:
> Fixes ticket #8302
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/avienc.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/avienc.c b/libavformat/avienc.c
> index ac0f04c354..5f143bccce 100644
> --- a/libavformat/avienc.c
> +++ b/libavformat/avienc.c
> @@ -909,7 +909,7 @@ static int avi_write_trailer(AVFormatContext *s)
>      AVIContext *avi = s->priv_data;
>      AVIOContext *pb = s->pb;
>      int res = 0;
> -    int i, j, n, nb_frames;
> +    int i, n, nb_frames;
>      int64_t file_size;
>
>      for (i = 0; i < s->nb_streams; i++) {
> @@ -962,10 +962,6 @@ static int avi_write_trailer(AVFormatContext *s)
>
>      for (i = 0; i < s->nb_streams; i++) {
>          AVIStream *avist = s->streams[i]->priv_data;
> -        for (j = 0; j < avist->indexes.ents_allocated /
> AVI_INDEX_CLUSTER_SIZE; j++)
> -            av_freep(&avist->indexes.cluster[j]);
> -        av_freep(&avist->indexes.cluster);
> -        avist->indexes.ents_allocated = avist->indexes.entry = 0;
>          if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
>              avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
>              avio_wl32(pb, avist->max_size);
> @@ -975,6 +971,19 @@ static int avi_write_trailer(AVFormatContext *s)
>      return res;
>  }
>
> +static void avi_deinit(AVFormatContext *s)
> +{
> +    for (int i = 0; i < s->nb_streams; i++) {
> +        AVIStream *avist = s->streams[i]->priv_data;
> +        if (!avist)
> +            continue;
> +        for (int j = 0; j < avist->indexes.ents_allocated /
> AVI_INDEX_CLUSTER_SIZE; j++)
> +            av_freep(&avist->indexes.cluster[j]);
> +        av_freep(&avist->indexes.cluster);
> +        avist->indexes.ents_allocated = avist->indexes.entry = 0;
> +    }
> +}
> +
>  #define OFFSET(x) offsetof(AVIContext, x)
>  #define ENC AV_OPT_FLAG_ENCODING_PARAM
>  static const AVOption options[] = {
> @@ -999,6 +1008,7 @@ AVOutputFormat ff_avi_muxer = {
>      .audio_codec    = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 :
> AV_CODEC_ID_AC3,
>      .video_codec    = AV_CODEC_ID_MPEG4,
>      .init           = avi_init,
> +    .deinit         = avi_deinit,
>      .write_header   = avi_write_header,
>      .write_packet   = avi_write_packet,
>      .write_trailer  = avi_write_trailer,
> --
> 2.23.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
James Almer Oct. 21, 2019, 8:38 p.m. UTC | #2
On 10/19/2019 11:18 AM, Paul B Mahol wrote:
> LGTM

Applied, thanks.
diff mbox

Patch

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index ac0f04c354..5f143bccce 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -909,7 +909,7 @@  static int avi_write_trailer(AVFormatContext *s)
     AVIContext *avi = s->priv_data;
     AVIOContext *pb = s->pb;
     int res = 0;
-    int i, j, n, nb_frames;
+    int i, n, nb_frames;
     int64_t file_size;
 
     for (i = 0; i < s->nb_streams; i++) {
@@ -962,10 +962,6 @@  static int avi_write_trailer(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         AVIStream *avist = s->streams[i]->priv_data;
-        for (j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
-            av_freep(&avist->indexes.cluster[j]);
-        av_freep(&avist->indexes.cluster);
-        avist->indexes.ents_allocated = avist->indexes.entry = 0;
         if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
             avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
             avio_wl32(pb, avist->max_size);
@@ -975,6 +971,19 @@  static int avi_write_trailer(AVFormatContext *s)
     return res;
 }
 
+static void avi_deinit(AVFormatContext *s)
+{
+    for (int i = 0; i < s->nb_streams; i++) {
+        AVIStream *avist = s->streams[i]->priv_data;
+        if (!avist)
+            continue;
+        for (int j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
+            av_freep(&avist->indexes.cluster[j]);
+        av_freep(&avist->indexes.cluster);
+        avist->indexes.ents_allocated = avist->indexes.entry = 0;
+    }
+}
+
 #define OFFSET(x) offsetof(AVIContext, x)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -999,6 +1008,7 @@  AVOutputFormat ff_avi_muxer = {
     .audio_codec    = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_AC3,
     .video_codec    = AV_CODEC_ID_MPEG4,
     .init           = avi_init,
+    .deinit         = avi_deinit,
     .write_header   = avi_write_header,
     .write_packet   = avi_write_packet,
     .write_trailer  = avi_write_trailer,