[FFmpeg-devel] [PATCH 1/2] lavfi: check for allocation failure in ff_insert_pad()

Paul B Mahol onemda at gmail.com
Thu Jul 11 00:00:47 CEST 2013


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavfilter/avfilter.c | 9 ++++++---
 libavfilter/internal.h | 3 ++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index c3228cd..b05f4e8 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -93,7 +93,7 @@ void ff_command_queue_pop(AVFilterContext *filter)
     av_free(c);
 }
 
-void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
+int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
                    AVFilterPad **pads, AVFilterLink ***links,
                    AVFilterPad *newpad)
 {
@@ -101,8 +101,10 @@ void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
 
     idx = FFMIN(idx, *count);
 
-    *pads  = av_realloc(*pads,  sizeof(AVFilterPad)   * (*count + 1));
-    *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
+    *pads  = av_realloc_f(*pads, *count + 1, sizeof(AVFilterPad));
+    *links = av_realloc_f(*links, *count + 1, sizeof(AVFilterLink*));
+    if (!*pads || !*links)
+        return AVERROR(ENOMEM);
     memmove(*pads  + idx + 1, *pads  + idx, sizeof(AVFilterPad)   * (*count - idx));
     memmove(*links + idx + 1, *links + idx, sizeof(AVFilterLink*) * (*count - idx));
     memcpy(*pads + idx, newpad, sizeof(AVFilterPad));
@@ -112,6 +114,7 @@ void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
     for (i = idx + 1; i < *count; i++)
         if (*links[i])
             (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
+    return 0;
 }
 
 int avfilter_link(AVFilterContext *src, unsigned srcpad,
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index f7df6d3..e3cba7c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -257,8 +257,9 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
  * @param pads Pointer to the pointer to the beginning of the list of pads
  * @param links Pointer to the pointer to the beginning of the list of links
  * @param newpad The new pad to add. A copy is made when adding.
+ * @return 0 in case of success, a negative AVERROR code on error
  */
-void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
+int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
                    AVFilterPad **pads, AVFilterLink ***links,
                    AVFilterPad *newpad);
 
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list