From 695b1d81117d6708a5db2d7115b73ef7c6e1a090 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Tue, 2 Jan 2018 01:58:35 +0100 Subject: lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc(). --- libavutil/mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libavutil/mem.c') 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 -- cgit v1.2.3