Make sure we release memory for the runtime generated backtraces.
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 15 May 2013 20:16:58 +0000 (16:16 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 15 May 2013 20:22:04 +0000 (16:22 -0400)
mono/metadata/object.c
mono/mini/mini-exceptions.c

index 7f0bf03c8dc84995e4bfed0559b550779bd45238..bfd6de51adbff271941af2d1232e4d0f6bc7fe88 100644 (file)
@@ -6094,9 +6094,15 @@ mono_print_unhandled_exception (MonoObject *exc)
                        MonoObject *other_exc = NULL;
                        str = mono_object_to_string (exc, &other_exc);
                        if (other_exc) {
+                               char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
+                               char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other_exc);
+                               
                                message = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
-                                       mono_exception_get_managed_backtrace ((MonoException*)exc),
-                                       mono_exception_get_managed_backtrace ((MonoException*)other_exc));
+                                       original_backtrace, nested_backtrace);
+
+                               g_free (original_backtrace);
+                               g_free (nested_backtrace);
+                               free_message = TRUE;
                        } else if (str) {
                                message = mono_string_to_utf8_checked (str, &error);
                                if (!mono_error_ok (&error)) {
index 4dc5b9d8e1a01b2683a317a6d13f1e96fcf6a5cd..66be5bef73bc84b2077374ea8d74fd6d5901f14e 100644 (file)
@@ -2722,9 +2722,14 @@ mono_invoke_unhandled_exception_hook (MonoObject *exc)
                if (str)
                        msg = mono_string_to_utf8 (str);
                else if (other) {
+                       char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
+                       char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);
+
                        msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
-                               mono_exception_get_managed_backtrace ((MonoException*)exc),
-                               mono_exception_get_managed_backtrace ((MonoException*)other));
+                               original_backtrace, nested_backtrace);
+
+                       g_free (original_backtrace);
+                       g_free (nested_backtrace);
                } else {
                        msg = g_strdup ("Nested exception trying to figure out what went wrong");
                }