diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-02-22 20:30:52 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-02-22 20:42:33 +0100 |
commit | 2c21d34ea44d38835f85b90de3cbbf54abb894be (patch) | |
tree | 1480ee83bf9f1d509a302c69a35524f91031f8fc /libavutil/mem.c | |
parent | 89c77b6b155cfd8c42db90a4d47f5cd034fddfc5 (diff) | |
download | ffmpeg-2c21d34ea44d38835f85b90de3cbbf54abb894be.tar.gz |
avutil/mem: do a small set of checks for memalign hack before freeing.
These can detect some kinds of memory and or pointer corruptions
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r-- | libavutil/mem.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c index 250b5f745e..6d3efaabfa 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -36,6 +36,7 @@ #include <malloc.h> #endif +#include "avassert.h" #include "avutil.h" #include "intreadwrite.h" #include "mem.h" @@ -148,6 +149,7 @@ void *av_realloc(void *ptr, size_t size) if (!ptr) return av_malloc(size); diff = ((char *)ptr)[-1]; + av_assert0(diff>0 && diff<=ALIGN); ptr = realloc((char *)ptr - diff, size + diff); if (ptr) ptr = (char *)ptr + diff; @@ -177,8 +179,11 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) void av_free(void *ptr) { #if CONFIG_MEMALIGN_HACK - if (ptr) - free((char *)ptr - ((char *)ptr)[-1]); + if (ptr) { + int v= ((char *)ptr)[-1]; + av_assert0(v>0 && v<=ALIGN); + free((char *)ptr - v); + } #elif HAVE_ALIGNED_MALLOC _aligned_free(ptr); #else |