---
 libavcodec/libvorbis.c |   49 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c
index b60b1f0..60e0b0f 100644
--- a/libavcodec/libvorbis.c
+++ b/libavcodec/libvorbis.c
@@ -108,17 +108,36 @@ static int xiph_len(int l)
     return 1 + l / 255 + l;
 }
 
+static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)
+{
+    OggVorbisContext *context = avccontext->priv_data;
+/*  ogg_packet op ; */
+
+    vorbis_analysis_wrote(&context->vd, 0);  /* notify vorbisenc this is EOF */
+
+    vorbis_block_clear(&context->vb);
+    vorbis_dsp_clear(&context->vd);
+    vorbis_info_clear(&context->vi);
+
+    av_freep(&avccontext->coded_frame);
+    av_freep(&avccontext->extradata);
+
+    return 0;
+}
+
 static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
 {
     OggVorbisContext *context = avccontext->priv_data;
     ogg_packet header, header_comm, header_code;
     uint8_t *p;
     unsigned int offset;
+    int ret;
 
     vorbis_info_init(&context->vi);
     if (oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
         av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder 
failed\n");
-        return -1;
+        ret = -1;
+        goto error;
     }
     vorbis_analysis_init(&context->vd, &context->vi);
     vorbis_block_init(&context->vd, &context->vb);
@@ -134,6 +153,10 @@ static av_cold int oggvorbis_encode_init(AVCodecContext 
*avccontext)
         header_code.bytes;
     p = avccontext->extradata =
             av_malloc(avccontext->extradata_size + 
FF_INPUT_BUFFER_PADDING_SIZE);
+    if (!p) {
+        ret = AVERROR(ENOMEM);
+        goto error;
+    }
     p[0]    = 2;
     offset  = 1;
     offset += av_xiphlacing(&p[offset], header.bytes);
@@ -156,8 +179,15 @@ static av_cold int oggvorbis_encode_init(AVCodecContext 
*avccontext)
     avccontext->frame_size = OGGVORBIS_FRAME_SIZE;
 
     avccontext->coded_frame = avcodec_alloc_frame();
+    if (!avccontext->coded_frame) {
+        ret = AVERROR(ENOMEM);
+        goto error;
+    }
 
     return 0;
+error:
+    oggvorbis_encode_close(avccontext);
+    return ret;
 }
 
 static int oggvorbis_encode_frame(AVCodecContext *avccontext,
@@ -233,23 +263,6 @@ static int oggvorbis_encode_frame(AVCodecContext 
*avccontext,
     return l;
 }
 
-static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)
-{
-    OggVorbisContext *context = avccontext->priv_data;
-/*  ogg_packet op ; */
-
-    vorbis_analysis_wrote(&context->vd, 0);  /* notify vorbisenc this is EOF */
-
-    vorbis_block_clear(&context->vb);
-    vorbis_dsp_clear(&context->vd);
-    vorbis_info_clear(&context->vi);
-
-    av_freep(&avccontext->coded_frame);
-    av_freep(&avccontext->extradata);
-
-    return 0;
-}
-
 AVCodec ff_libvorbis_encoder = {
     .name           = "libvorbis",
     .type           = AVMEDIA_TYPE_AUDIO,
-- 
1.7.1

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

Reply via email to