1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 7c2e6c7..f910288 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -429,14 +429,23 @@ static int bf_action_cb(int action, struct gui_synclist* list)
 {
     if (action == ACTION_STD_OK)
     {
-        splash(HZ/1, "Attempting a 64k allocation");
-        int handle = core_alloc("test", 64<<10);
-        splash(HZ/2, (handle > 0) ? "Success":"Fail");
-        /* for some reason simplelist doesn't allow adding items here if
-         * info.get_name is given, so use normal list api */
-        gui_synclist_set_nb_items(list, core_get_num_blocks());
-        if (handle > 0)
-            core_free(handle);
+        if (gui_synclist_get_sel_pos(list) == 0)
+        {
+            splash(HZ/2, "Freeing test handle");
+            splash(HZ/2, "New alloc should trigger compact");
+            core_test_free();
+        }
+        else
+        {
+            splash(HZ/1, "Attempting a 64k allocation");
+            int handle = core_alloc("test", 64<<10);
+            splash(HZ/2, (handle > 0) ? "Success":"Fail");
+            /* for some reason simplelist doesn't allow adding items here if
+             * info.get_name is given, so use normal list api */
+            gui_synclist_set_nb_items(list, core_get_num_blocks());
+            if (handle > 0)
+                core_free(handle);
+        }
         action = ACTION_REDRAW;
     }
     else if (action == ACTION_NONE)
diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c
index 2250f5c..919ffab 100644
--- a/firmware/core_alloc.c
+++ b/firmware/core_alloc.c
@@ -6,6 +6,7 @@
 
 /* not static so it can be discovered by core_get_data() */
 struct buflib_context core_ctx;
+static int test_alloc;
 void core_allocator_init(void)
 {
     buffer_init();
@@ -13,6 +14,14 @@ void core_allocator_init(void)
     void *start = buffer_get_buffer(&size);
     buflib_init(&core_ctx, start, size);
     buffer_release_buffer(size);
+
+    test_alloc = core_alloc("test", 112);
+}
+
+void core_test_free(void)
+{
+    if (test_alloc > 0)
+        test_alloc = core_free(test_alloc);
 }
 
 int core_alloc(const char* name, size_t size)
diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h
index f5206c9..aebfd7a 100644
--- a/firmware/include/core_alloc.h
+++ b/firmware/include/core_alloc.h
@@ -28,6 +28,8 @@ int  core_get_num_blocks(void);
 void core_print_block_at(int block_num, char* buf, size_t bufsize);
 #endif
 
+void core_test_free(void);
+
 static inline void* core_get_data(int handle)
 {
     extern struct buflib_context core_ctx;