Example to demonstrate usage of mbed_stats_stack_get_each API

Fork of heap_stats_example by mbed_example

Revision:
5:dcc8640ad89c
Parent:
4:539750137652
--- a/main.cpp	Thu Aug 30 16:51:05 2018 +0000
+++ b/main.cpp	Fri Aug 31 16:52:13 2018 +0000
@@ -8,9 +8,12 @@
     int cnt = osThreadGetCount();
     mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));
 
-    cnt = mbed_stats_stack_get_each(stats, cnt);
-    for (int i = 0; i < cnt; i++) {
-        printf("Thread: 0x%X, Stack size: %u, Max stack: %u\r\n", 
-                stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
+    if (stats) {
+        cnt = mbed_stats_stack_get_each(stats, cnt);
+        for (int i = 0; i < cnt; i++) {
+            printf("Thread: 0x%lx, Stack size: %u, Max stack: %u\r\n", 
+                    stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
+        }
+        free(stats);
     }
 }