[libav-devel] [PATCH v2] ogg: check malloc calls

Nidhi Makhijani nidhimj22 at gmail.com
Sat Jun 14 06:15:44 CEST 2014


---
set extradata_size only on success
 libavformat/oggparsespeex.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index 6d70e99..15f1be0 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -47,6 +47,8 @@ static int speex_header(AVFormatContext *s, int idx) {
 
     if (!spxp) {
         spxp = av_mallocz(sizeof(*spxp));
+        if (!spxp)
+            return AVERROR(ENOMEM);
         os->private = spxp;
     }
 
@@ -72,9 +74,12 @@ static int speex_header(AVFormatContext *s, int idx) {
         if (frames_per_packet)
             spxp->packet_size *= frames_per_packet;
 
-        st->codec->extradata_size = os->psize;
         st->codec->extradata = av_malloc(st->codec->extradata_size
                                          + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (!st->codec->extradata)
+            return AVERROR(ENOMEM);
+
+        st->codec->extradata_size = os->psize;
         memcpy(st->codec->extradata, p, st->codec->extradata_size);
 
         avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
-- 
1.9.1



More information about the libav-devel mailing list