[FFmpeg-cvslog] avformat/utils: functions that add entries should not destroy the whole list on failure

Michael Niedermayer git at videolan.org
Wed Sep 11 12:31:36 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Sep 11 12:13:44 2013 +0200| [8c9d6ee4f2ad84114cf65944d91157069825423e] | committer: Michael Niedermayer

avformat/utils: functions that add entries should not destroy the whole list on failure

The caller does not expect this, and in case of adding new streams would then
not even be able to deallocate them anymore.

This reverts a hunk from "avformat: Use av_reallocp_array() where suitable"

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8c9d6ee4f2ad84114cf65944d91157069825423e
---

 libavformat/utils.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9c21ae0..4d4b701 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3296,11 +3296,14 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
 {
     AVStream *st;
     int i;
+    AVStream **streams;
 
-    if (av_reallocp_array(&s->streams, s->nb_streams + 1, sizeof(*s->streams)) < 0) {
-        s->nb_streams = 0;
+    if (s->nb_streams >= INT_MAX/sizeof(*streams))
         return NULL;
-    }
+    streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));
+    if (!streams)
+        return NULL;
+    s->streams = streams;
 
     st = av_mallocz(sizeof(AVStream));
     if (!st)
@@ -3404,6 +3407,7 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
 {
     int i, j;
     AVProgram *program=NULL;
+    void *tmp;
 
     if (idx >= ac->nb_streams) {
         av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
@@ -3418,12 +3422,10 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
             if(program->stream_index[j] == idx)
                 return;
 
-        if (av_reallocp_array(&program->stream_index,
-                              program->nb_stream_indexes + 1,
-                              sizeof(*program->stream_index)) < 0) {
-            program->nb_stream_indexes = 0;
+        tmp = av_realloc(program->stream_index, sizeof(unsigned int)*(program->nb_stream_indexes+1));
+        if(!tmp)
             return;
-        }
+        program->stream_index = tmp;
         program->stream_index[program->nb_stream_indexes++] = idx;
         return;
     }



More information about the ffmpeg-cvslog mailing list