]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
trying to fix av_realloc()
authormichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 13 Aug 2006 21:09:00 +0000 (21:09 +0000)
committermichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 13 Aug 2006 21:09:00 +0000 (21:09 +0000)
git-svn-id: file:///var/local/repositories/ffmpeg/trunk@5996 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavutil/mem.c

index 61d886dc5d0a25e03325f69e0cc4f15df9ad52e4..cdfefd605502c4c24e96c68b95fc97bdccf4bc66 100644 (file)
@@ -50,7 +50,7 @@ void *av_malloc(unsigned int size)
 #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 @@ void *av_realloc(void *ptr, unsigned int size)
 
 #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;
 }