From 1191ffa0ebd23dba9ef82a185fe5ada4f0847c93 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Mon, 29 Jun 2009 16:13:25 +0000 Subject: [PATCH] Change demangler to not use excessive space from stack Replaces alloca with xmalloc calls. This should fix bug 197988. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10385 --- coregrind/m_demangle/cp-demangle.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/coregrind/m_demangle/cp-demangle.c b/coregrind/m_demangle/cp-demangle.c index 00aba99d6f..6db386c025 100644 --- a/coregrind/m_demangle/cp-demangle.c +++ b/coregrind/m_demangle/cp-demangle.c @@ -4426,16 +4426,11 @@ d_demangle_callback (const char *mangled, int options, cplus_demangle_init_info (mangled, options, strlen (mangled), &di); { -#ifdef CP_DYNAMIC_ARRAYS - __extension__ struct demangle_component comps[di.num_comps]; - __extension__ struct demangle_component *subs[di.num_subs]; - - di.comps = comps; - di.subs = subs; -#else - di.comps = alloca (di.num_comps * sizeof (*di.comps)); - di.subs = alloca (di.num_subs * sizeof (*di.subs)); -#endif + /* The original demangler uses alloca here with large allocations + for template-heavy code, e.g. when using Boost. This + is bad for Valgrind tools with limited stack size */ + di.comps = xmalloc(di.num_comps * sizeof (*di.comps)); + di.subs = xmalloc(di.num_subs * sizeof (*di.subs)); if (type) dc = cplus_demangle_type (&di); @@ -4456,6 +4451,9 @@ d_demangle_callback (const char *mangled, int options, status = (dc != NULL) ? cplus_demangle_print_callback (options, dc, callback, opaque) : 0; + + free(di.comps); + free(di.subs); } return status; -- 2.47.3