diff mbox series

[FFmpeg-devel,21/21] avformat/icodec: Simplify cleanup after read_header failure

Message ID 20200322034756.29907-21-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/21] avformat/nsvdec: Use av_packet_move_ref() for packet ownership transfer
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 22, 2020, 3:47 a.m. UTC
by setting the FF_INPUTFORMAT_HEADER_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/icodec.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/icodec.c b/libavformat/icodec.c
index b47fa98f80..9449bb7315 100644
--- a/libavformat/icodec.c
+++ b/libavformat/icodec.c
@@ -96,10 +96,8 @@  static int read_header(AVFormatContext *s)
             break;
 
         st = avformat_new_stream(s, NULL);
-        if (!st) {
-            av_freep(&ico->images);
+        if (!st)
             return AVERROR(ENOMEM);
-        }
 
         st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
         st->codecpar->width      = avio_r8(pb);
@@ -113,7 +111,6 @@  static int read_header(AVFormatContext *s)
         ico->images[i].size   = avio_rl32(pb);
         if (ico->images[i].size <= 0) {
             av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size);
-            av_freep(&ico->images);
             return AVERROR_INVALIDDATA;
         }
         ico->images[i].offset = avio_rl32(pb);
@@ -130,7 +127,6 @@  static int read_header(AVFormatContext *s)
             break;
         case 40:
             if (ico->images[i].size < 40) {
-                av_freep(&ico->images);
                 return AVERROR_INVALIDDATA;
             }
             st->codecpar->codec_id = AV_CODEC_ID_BMP;
@@ -143,7 +139,6 @@  static int read_header(AVFormatContext *s)
             break;
         default:
             avpriv_request_sample(s, "codec %d", codec);
-            av_freep(&ico->images);
             return AVERROR_INVALIDDATA;
         }
     }
@@ -224,4 +219,5 @@  AVInputFormat ff_ico_demuxer = {
     .read_packet    = read_packet,
     .read_close     = ico_read_close,
     .flags          = AVFMT_NOTIMESTAMPS,
+    .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
 };