]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/mem.c
log: fix compilation failure on mingw due to reference to undefined set_color256
[ffmpeg] / libavutil / mem.c
index d711350fdac7ec57b8b3e8c312594e5e4ff05ac0..8ec226b17aee2cb57e873ed83bc12f175ce244aa 100644 (file)
@@ -61,9 +61,10 @@ void  free(void *ptr);
 
 #define ALIGN (HAVE_AVX ? 32 : 16)
 
-/* You can redefine av_malloc and av_free in your project to use your
-   memory allocator. You do not need to suppress this file because the
-   linker will do it automatically. */
+/* NOTE: if you want to override these functions with your own
+ * implementations (not recommended) you have to link libav* as
+ * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
+ * Note that this will cost performance. */
 
 static size_t max_alloc_size= INT_MAX;
 
@@ -93,6 +94,8 @@ void *av_malloc(size_t size)
     if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
     if (posix_memalign(&ptr,ALIGN,size))
         ptr = NULL;
+#elif HAVE_ALIGNED_MALLOC
+    ptr = _aligned_malloc(size, ALIGN);
 #elif HAVE_MEMALIGN
     ptr = memalign(ALIGN,size);
     /* Why 64?
@@ -122,8 +125,14 @@ void *av_malloc(size_t size)
 #else
     ptr = malloc(size);
 #endif
-    if(!ptr && !size)
+    if(!ptr && !size) {
+        size = 1;
         ptr= av_malloc(1);
+    }
+#if CONFIG_MEMORY_POISONING
+    if (ptr)
+        memset(ptr, 0x2a, size);
+#endif
     return ptr;
 }
 
@@ -144,6 +153,8 @@ void *av_realloc(void *ptr, size_t size)
     ptr= realloc((char*)ptr - diff, size + diff);
     if(ptr) ptr = (char*)ptr + diff;
     return ptr;
+#elif HAVE_ALIGNED_MALLOC
+    return _aligned_realloc(ptr, size + !size, ALIGN);
 #else
     return realloc(ptr, size + !size);
 #endif
@@ -169,6 +180,8 @@ void av_free(void *ptr)
 #if CONFIG_MEMALIGN_HACK
     if (ptr)
         free((char*)ptr - ((char*)ptr)[-1]);
+#elif HAVE_ALIGNED_MALLOC
+    _aligned_free(ptr);
 #else
     free(ptr);
 #endif