]> git.sesse.net Git - ffmpeg/commitdiff
lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc().
authorCarl Eugen Hoyos <ceffmpeg@gmail.com>
Tue, 2 Jan 2018 00:58:35 +0000 (01:58 +0100)
committerCarl Eugen Hoyos <ceffmpeg@gmail.com>
Thu, 4 Jan 2018 04:39:18 +0000 (05:39 +0100)
libavutil/mem.c

index 0729e1dd50684371e7d5e34ed33011971396cf8e..6149755a6b88eef2b071a208088594ba04fde68d 100644 (file)
@@ -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