Index: libavutil/mem.c
===================================================================
--- libavutil/mem.c	(revision 25591)
+++ libavutil/mem.c	(working copy)
@@ -61,6 +61,11 @@
    memory allocator. You do not need to suppress this file because the
    linker will do it automatically. */
 
+static int alloced[1<<20];
+static void *alloced_ptr[1<<20];
+static int num_allocs = 0;
+#undef fprintf
+
 void *av_malloc(unsigned int size)
 {
     void *ptr = NULL;
@@ -113,6 +118,14 @@
 #else
     ptr = malloc(size);
 #endif
+    alloced[num_allocs] = size;
+    alloced_ptr[num_allocs] = ptr;
+    num_allocs++;
+    unsigned int sum = 0;
+    for(int i = 0; i < num_allocs; i++)
+        sum += alloced[i];
+    #undef printf
+    printf("%d\n",sum);
     return ptr;
 }
 
@@ -121,6 +134,7 @@
 #if CONFIG_MEMALIGN_HACK
     int diff;
 #endif
+    void *newptr;
 
     /* let's disallow possible ambiguous cases */
     if(size > (INT_MAX-16) )
@@ -130,14 +144,30 @@
     //FIXME this isn't aligned correctly, though it probably isn't needed
     if(!ptr) return av_malloc(size);
     diff= ((char*)ptr)[-1];
-    return (char*)realloc((char*)ptr - diff, size + diff) + diff;
+    newptr = (char*)realloc((char*)ptr - diff, size + diff) + diff;
 #else
-    return realloc(ptr, size);
+    newptr = realloc(ptr, size);
 #endif
+    for(int i = 0; i < num_allocs; i++)
+        if(alloced_ptr[i] == ptr)
+        {
+            alloced[i] = size;
+            alloced_ptr[i] = newptr;
+            break;
+        }
+    return newptr;
 }
 
 void av_free(void *ptr)
 {
+    if(ptr)
+    for(int i = 0; i < num_allocs; i++)
+        if(alloced_ptr[i] == ptr)
+        {
+            alloced[i] = 0;
+            alloced_ptr[i] = NULL;
+            break;
+        }
     /* XXX: this test should not be needed on most libcs */
     if (ptr)
 #if CONFIG_MEMALIGN_HACK
