Move large structure off the stack.
The struct unw_addr_space is very large (at least 13624 bytes on arm),
but is on the stack in the function map_create_list.
Allocate this function when needed instead of putting it on the stack.
Test: Built and ran backtrace_test on an angler. Stepped through the
Test: modified code and verified it is called and allocated properly.
Test: Ran valgrind on the backtrace_test.local_trace to verify that
Test: the memory is not leaked.
(cherry picked from commit 50270d3ef2127372c0ae6aefd9be255ab901f573)
diff --git a/src/os-linux.c b/src/os-linux.c
index 7062a1b..8dc1ebf 100644
@@ -40,7 +40,7 @@
struct map_info *map_list = NULL;
struct map_info *cur_map;
unw_addr_space_t as = NULL;
- struct unw_addr_space local_as;
+ struct unw_addr_space* local_as = NULL;
void* as_arg = NULL;
if (maps_init (&mi, pid) < 0)
@@ -100,8 +100,14 @@
if (map_create_type == UNW_MAP_CREATE_LOCAL)
- as = &local_as;
- unw_local_access_addr_space_init (as);
+ // This is a very large structure, so allocate it.
+ if (local_as == NULL)
+ local_as = (struct unw_addr_space*) malloc(sizeof(*local_as));
+ if (local_as != NULL)
+ as = local_as;
+ unw_local_access_addr_space_init (as);
@@ -147,6 +153,8 @@
/* End of ANDROID update. */