[FFmpeg-cvslog] avfilter/formats: free the correct pointer in ADD_FORMAT()

Michael Niedermayer git at videolan.org
Fri Nov 21 22:25:09 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Nov 21 22:13:44 2014 +0100| [75819fafd8213875af2bfbe5ea821ae5b8d419f9] | committer: Michael Niedermayer

avfilter/formats: free the correct pointer in ADD_FORMAT()

Also only free it when it was not previously allocated to return to the
state prior to the failing function call

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

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

 libavfilter/formats.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 2fc07eb..42afcf4 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -314,6 +314,7 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts)
 #define ADD_FORMAT(f, fmt, type, list, nb)                  \
 do {                                                        \
     type *fmts;                                             \
+    void *oldf = *f;                                        \
                                                             \
     if (!(*f) && !(*f = av_mallocz(sizeof(**f))))           \
         return AVERROR(ENOMEM);                             \
@@ -321,7 +322,8 @@ do {                                                        \
     fmts = av_realloc((*f)->list,                           \
                       sizeof(*(*f)->list) * ((*f)->nb + 1));\
     if (!fmts) {                                            \
-        av_freep(&f);                                       \
+        if (!oldf)                                          \
+            av_freep(f);                                    \
         return AVERROR(ENOMEM);                             \
     }                                                       \
                                                             \



More information about the ffmpeg-cvslog mailing list