]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Change demangler to not use excessive space from stack
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 29 Jun 2009 16:13:25 +0000 (16:13 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 29 Jun 2009 16:13:25 +0000 (16:13 +0000)
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

index 00aba99d6f3881718778202ea4886c1dd217ccd6..6db386c0251b0dbbe1ce270510f2a6c9cd58bee6 100644 (file)
@@ -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;