From 5cd754bca290775ec2dbbf88597ab58e0482efca Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Sun, 20 Mar 2011 19:39:20 +0100 Subject: Introduce av_realloc_f. av_realloc_f helps avoiding memory-leaks in typical uses of realloc. Signed-off-by: Nicolas George Signed-off-by: Michael Niedermayer --- libavutil/mem.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libavutil/mem.h') diff --git a/libavutil/mem.h b/libavutil/mem.h index ffdbb98d94..179e12f32f 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -87,6 +87,16 @@ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1); */ void *av_realloc(void *ptr, size_t size) av_alloc_size(2); +/** + * Allocate or reallocate a block of memory. + * This function does the same thing as av_realloc, except: + * - It takes two arguments and checks the result of the multiplication for + * integer overflow. + * - It frees the input block in case of failure, thus avoiding the memory + * leak with the classic "buf = realloc(buf); if (!buf) return -1;". + */ +void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); + /** * Free a memory block which has been allocated with av_malloc(z)() or * av_realloc(). -- cgit v1.2.3