summaryrefslogtreecommitdiffstats
path: root/libavutil/mem.c
diff options
context:
space:
mode:
authorNicolas George <nicolas.george@normalesup.org>2011-03-20 19:39:20 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-09-28 18:13:52 +0200
commit5cd754bca290775ec2dbbf88597ab58e0482efca (patch)
treec946720bf6f447ab32fedefe664f22ae053fd19e /libavutil/mem.c
parentb2600509fef4d77645491f208b8113c372a32110 (diff)
downloadffmpeg-streaming-5cd754bca290775ec2dbbf88597ab58e0482efca.zip
ffmpeg-streaming-5cd754bca290775ec2dbbf88597ab58e0482efca.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>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r--libavutil/mem.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 44bfc8c..a58f432 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -143,6 +143,21 @@ void *av_realloc(void *ptr, size_t size)
#endif
}
+void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
+{
+ size_t size;
+ void *r;
+
+ if (av_size_mult(elsize, nelem, &size)) {
+ av_free(ptr);
+ return NULL;
+ }
+ r = av_realloc(ptr, size);
+ if (!r && size)
+ av_free(ptr);
+ return r;
+}
+
void av_free(void *ptr)
{
#if CONFIG_MEMALIGN_HACK
OpenPOWER on IntegriCloud