This puts av_fast_malloc*() in line with av_fast_realloc().
Signed-off-by: James Almer <[email protected]>
---
libavutil/mem.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 471b49f8e7..1b0e39eb89 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -513,6 +513,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));
@@ -520,7 +521,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));
--
2.31.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".