diff options
author | James Almer <jamrial@gmail.com> | 2021-05-23 11:29:04 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2021-05-27 10:29:59 -0300 |
commit | 918fc9a0ed4e9202341ffb3e7e4b72b4387dfe0a (patch) | |
tree | 95d9a1592ca72524139a7ff82e5ac87c781c7bf0 /libavutil/mem.c | |
parent | 786be70e28fe739b8e49893fa13ae4652a68d1ea (diff) | |
download | ffmpeg-918fc9a0ed4e9202341ffb3e7e4b72b4387dfe0a.tar.gz |
avutil/mem: check for max_alloc_size in av_fast_malloc()
This puts av_fast_malloc*() in line with av_fast_realloc().
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r-- | libavutil/mem.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c index 3c014f3f68..a52d33d4a6 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -512,6 +512,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) { + size_t max_size; void *val; memcpy(&val, ptr, sizeof(val)); @@ -519,7 +520,15 @@ static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, i av_assert0(val || !min_size); return; } - min_size = FFMAX(min_size + min_size / 16 + 32, min_size); + + max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed); + + if (min_size > max_size) { + av_freep(ptr); + *size = 0; + return; + } + min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size)); av_freep(ptr); val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); memcpy(ptr, &val, sizeof(val)); |