[FFmpeg-cvslog] lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc().

Carl Eugen Hoyos git at videolan.org
Thu Jan 4 06:40:16 EET 2018


ffmpeg | branch: master | Carl Eugen Hoyos <ceffmpeg at gmail.com> | Tue Jan  2 01:58:35 2018 +0100| [695b1d81117d6708a5db2d7115b73ef7c6e1a090] | committer: Carl Eugen Hoyos

lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc().

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

 libavutil/mem.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 0729e1dd50..6149755a6b 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -466,7 +466,12 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
     if (min_size <= *size)
         return ptr;
 
-    min_size = FFMAX(min_size + min_size / 16 + 32, min_size);
+    if (min_size > max_alloc_size - 32) {
+        *size = 0;
+        return NULL;
+    }
+
+    min_size = FFMIN(max_alloc_size - 32, FFMAX(min_size + min_size / 16 + 32, min_size));
 
     ptr = av_realloc(ptr, min_size);
     /* we could set this to the unmodified min_size but this is safer



More information about the ffmpeg-cvslog mailing list