aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/mem.h
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2011-03-20 19:39:20 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-10-01 20:48:59 +0200
commita75b5a89d11b80e89bb2ff723cfcc270480dc06d (patch)
tree47b66e29c2cb60c83e32f5bcb0c1f37c7e972fe6 /libavutil/mem.h
parent651e21f584d92709d58242dcad49b238e54dfdd5 (diff)
downloadffmpeg-a75b5a89d11b80e89bb2ff723cfcc270480dc06d.tar.gz
Introduce av_realloc_f.
av_realloc_f helps avoiding memory-leaks in typical uses of realloc. Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 5cd754bca290775ec2dbbf88597ab58e0482efca)
Diffstat (limited to 'libavutil/mem.h')
-rw-r--r--libavutil/mem.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 241b453257..d3e82b2ace 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -88,6 +88,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().
* @param ptr Pointer to the memory block which should be freed.