yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / direct / test-framework / yaffs_osglue.c
index ca5efc069e366f87479544923cb1bc6f7f6596a1..94ca24dfd225a73bde9924f6c51a73672ed1c89b 100644 (file)
@@ -106,7 +106,13 @@ static void *bg_gc_func(void *dummy)
 
                while ((dev = yaffs_next_dev()) != NULL) {
                        result = yaffs_do_background_gc_reldev(dev, urgent);
 
                while ((dev = yaffs_next_dev()) != NULL) {
                        result = yaffs_do_background_gc_reldev(dev, urgent);
-                       if (result > 0)
+
+                       /* result is 1 if more than half the free space is
+                        * erased.
+                        * If less than half the free space is erased then it is
+                        * worth doing another background_gc operation sooner.
+                        */
+                       if (result == 0)
                                next_urgent = 1;
                }
 
                                next_urgent = 1;
                }
 
@@ -165,6 +171,48 @@ u32 yaffsfs_CurrentTime(void)
  * Functions to allocate and free memory.
  */
 
  * Functions to allocate and free memory.
  */
 
+
+static unsigned malloc_high_water;
+static unsigned malloc_currently_allocated;
+
+#ifdef CONFIG_YAFFS_MONITOR_MALLOC
+
+#include <malloc.h>
+static void yaffsfs_malloc_add(void *ptr)
+{
+       unsigned this_size = malloc_usable_size(ptr);
+       malloc_currently_allocated += this_size;
+
+       if (malloc_currently_allocated > malloc_high_water)
+               malloc_high_water = malloc_currently_allocated;
+}
+
+static void yaffsfs_malloc_remove(void *ptr)
+{
+       unsigned this_size = malloc_usable_size(ptr);
+       malloc_currently_allocated -= this_size;
+}
+#else
+static void yaffsfs_malloc_add(void *ptr)
+{
+       (void)ptr;
+}
+
+static void yaffsfs_malloc_remove(void *ptr)
+{
+       (void)ptr;
+}
+#endif
+
+void yaffsfs_get_malloc_values(unsigned *current, unsigned *high_water)
+{
+       if (current)
+               *current = malloc_currently_allocated;
+       if(high_water)
+               *high_water = malloc_high_water;
+}
+
+
 #ifdef CONFIG_YAFFS_TEST_MALLOC
 
 static int yaffs_kill_alloc = 0;
 #ifdef CONFIG_YAFFS_TEST_MALLOC
 
 static int yaffs_kill_alloc = 0;
@@ -182,6 +230,7 @@ void *yaffsfs_malloc(size_t size)
        this = malloc(size);
        if(this)
                total_malloced += size;
        this = malloc(size);
        if(this)
                total_malloced += size;
+       yaffsfs_malloc_add(this);
        return this;
 }
 
        return this;
 }
 
@@ -189,13 +238,19 @@ void *yaffsfs_malloc(size_t size)
 
 void *yaffsfs_malloc(size_t size)
 {
 
 void *yaffsfs_malloc(size_t size)
 {
-       return malloc(size);
+       void *this = malloc(size);
+       yaffsfs_malloc_add(this);
+       return this;
 }
 
 #endif
 
 }
 
 #endif
 
+
+
+
 void yaffsfs_free(void *ptr)
 {
 void yaffsfs_free(void *ptr)
 {
+       yaffsfs_malloc_remove(ptr);
        free(ptr);
 }
 
        free(ptr);
 }