diff mbox series

[FFmpeg-devel,3/5] avcodec/libvorbisenc: Fix memleak upon error

Message ID HE1PR0301MB2154F763707FC5D996B6F2598F4D9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec: Remove redundant freeing of extradata of encoders
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 15, 2021, 2:04 a.m. UTC
The vorbis_comment struct used to during codec initialization
would leak in case an error happened after its initialization
(e.g. if the allocation of extradata failed). This has been fixed.

Given that said struct is only used when writing the header, it has
also been moved from the context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/libvorbisenc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index 9d36457328..b556280a95 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -47,7 +47,6 @@  typedef struct LibvorbisEncContext {
     AVFifoBuffer *pkt_fifo;             /**< output packet buffer           */
     int eof;                            /**< end-of-file flag               */
     int dsp_initialized;                /**< vd has been initialized        */
-    vorbis_comment vc;                  /**< VorbisComment info             */
     double iblock;                      /**< impulse block bias option      */
     AVVorbisParseContext *vp;           /**< parse context to get durations */
     AudioFrameQueue afq;                /**< frame queue for timestamps     */
@@ -206,6 +205,7 @@  static av_cold int libvorbis_encode_init(AVCodecContext *avctx)
 {
     LibvorbisEncContext *s = avctx->priv_data;
     ogg_packet header, header_comm, header_code;
+    vorbis_comment vc;
     uint8_t *p;
     unsigned int offset;
     int ret;
@@ -227,12 +227,14 @@  static av_cold int libvorbis_encode_init(AVCodecContext *avctx)
         goto error;
     }
 
-    vorbis_comment_init(&s->vc);
+    vorbis_comment_init(&vc);
     if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT))
-        vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT);
+        vorbis_comment_add_tag(&vc, "encoder", LIBAVCODEC_IDENT);
 
-    if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
-                                         &header_code))) {
+    ret = vorbis_analysis_headerout(&s->vd, &vc, &header, &header_comm,
+                                    &header_code);
+    vorbis_comment_clear(&vc);
+    if (ret) {
         ret = vorbis_error_to_averror(ret);
         goto error;
     }
@@ -264,8 +266,6 @@  static av_cold int libvorbis_encode_init(AVCodecContext *avctx)
         return ret;
     }
 
-    vorbis_comment_clear(&s->vc);
-
     avctx->frame_size = LIBVORBIS_FRAME_SIZE;
     ff_af_queue_init(avctx, &s->afq);