changeset 95:a87f3ae8c46f libavutil

trying to fix av_realloc()
author michael
date Sun, 13 Aug 2006 21:09:00 +0000
parents 7ac2b9550c6b
children 7d343463873b
files mem.c
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mem.c	Sun Aug 13 00:47:16 2006 +0000
+++ b/mem.c	Sun Aug 13 21:09:00 2006 +0000
@@ -50,7 +50,7 @@
 #endif
 
     /* let's disallow possible ambiguous cases */
-    if(size > (INT_MAX-16) )
+    if(size > (INT_MAX-16) || !size)
         return NULL;
 
 #ifdef MEMALIGN_HACK
@@ -109,14 +109,16 @@
 
 #ifndef MEMALIGN_HACK
     ptr= realloc(ptr, size);
-    if(((int)ptr&15) || !ptr)
+assert(((int)((void*)0)&15) == 0); //for the null pointer pedants
+    if(!((int)ptr&15))
         return ptr;
 #endif
 
     ptr2= av_malloc(size);
     if(ptr && ptr2)
         memcpy(ptr2, ptr, size);
-    av_free(ptr);
+    if(ptr2 || !size)
+        av_free(ptr);
 
     return ptr2;
 }