Fixes a segfault if init() fails before initializing the dsp state
---
 libavcodec/libvorbis.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c
index ee24b4f..1fc9e1d 100644
--- a/libavcodec/libvorbis.c
+++ b/libavcodec/libvorbis.c
@@ -52,6 +52,7 @@ typedef struct OggVorbisContext {
     uint8_t buffer[BUFFER_SIZE];        /**< output packet buffer           */
     int buffer_index;                   /**< current buffer position        */
     int eof;                            /**< end-of-file flag               */
+    int dsp_initialized;                /**< vd has been initialized        */
     vorbis_comment vc;                  /**< VorbisComment info             */
     ogg_packet op;                      /**< ogg packet                     */
     double iblock;                      /**< impulse block bias option      */
@@ -147,7 +148,8 @@ static av_cold int oggvorbis_encode_close(AVCodecContext 
*avctx)
     OggVorbisContext *s = avctx->priv_data;
 
     /* notify vorbisenc this is EOF */
-    vorbis_analysis_wrote(&s->vd, 0);
+    if (s->dsp_initialized)
+        vorbis_analysis_wrote(&s->vd, 0);
 
     vorbis_block_clear(&s->vb);
     vorbis_dsp_clear(&s->vd);
@@ -176,6 +178,7 @@ static av_cold int oggvorbis_encode_init(AVCodecContext 
*avctx)
         ret = vorbis_error_to_averror(ret);
         goto error;
     }
+    s->dsp_initialized = 1;
     if ((ret = vorbis_block_init(&s->vd, &s->vb))) {
         ret = vorbis_error_to_averror(ret);
         goto error;
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to