aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/mem.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-12-25 18:43:58 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-12-25 18:55:43 +0100
commit5a8e994287d8ef181c0a5eac537547d7059b4524 (patch)
treeb1dd9dd0e6812e4a13f97ac8e09cb464cc4a71d0 /libavutil/mem.c
parent5e9a56a0350c518cd4b38845aff49d41a9c952ae (diff)
downloadffmpeg-5a8e994287d8ef181c0a5eac537547d7059b4524.tar.gz
mem: add av_max_alloc() to limit the maximum amount that may be allocated in one piece
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r--libavutil/mem.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 4acc43b2ef..f965339ce9 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -65,7 +65,11 @@ void free(void *ptr);
memory allocator. You do not need to suppress this file because the
linker will do it automatically. */
-#define MAX_MALLOC_SIZE INT_MAX
+static size_t max_alloc_size= INT_MAX;
+
+void av_max_alloc(size_t max){
+ max_alloc_size = max;
+}
void *av_malloc(size_t size)
{
@@ -75,7 +79,7 @@ void *av_malloc(size_t size)
#endif
/* let's disallow possible ambiguous cases */
- if (size > (MAX_MALLOC_SIZE-32))
+ if (size > (max_alloc_size-32))
return NULL;
#if CONFIG_MEMALIGN_HACK
@@ -130,7 +134,7 @@ void *av_realloc(void *ptr, size_t size)
#endif
/* let's disallow possible ambiguous cases */
- if (size > (MAX_MALLOC_SIZE-16))
+ if (size > (max_alloc_size-32))
return NULL;
#if CONFIG_MEMALIGN_HACK