File 6773-erts-Do-not-build-stacktrace-on-process-heap.patch of Package erlang

From e19c3780296413660c3a7650435cf057be1817d2 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Mon, 28 Aug 2023 21:32:42 +0200
Subject: [PATCH 3/3] erts: Do not build stacktrace on process heap

when max_heap_size has been reached.
Not sure it would be a problem but it seem like it could be.
---
 erts/emulator/beam/erl_gc.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/erts/emulator/beam/erl_gc.c b/erts/emulator/beam/erl_gc.c
index 7ae51b6843..6053a68a57 100644
--- a/erts/emulator/beam/erl_gc.c
+++ b/erts/emulator/beam/erl_gc.c
@@ -3724,7 +3724,7 @@ reached_max_heap_size(Process *p, Uint total_heap_size,
         if (max_heap_flags & MAX_HEAP_SIZE_LOG) {
             int alive = erts_is_alive;
             erts_dsprintf_buf_t *dsbufp = erts_create_logger_dsbuf();
-            Eterm *o_hp, *hp, args = NIL;
+            Eterm *hp, args = NIL, stacktrace;
             ErtsHeapFactory hfact;
 
             /* Build the format message */
@@ -3741,13 +3741,11 @@ reached_max_heap_size(Process *p, Uint total_heap_size,
             erts_dsprintf(dsbufp, "     Stacktrace:         ~p~n");
 
             /* Build the args in reverse order */
-            o_hp = hp = erts_alloc(ERTS_ALC_T_TMP, 2*(alive ? 9 : 8) * sizeof(Eterm));
-            erts_factory_proc_init(&hfact, p);
-            args = CONS(hp, erts_build_stacktrace(&hfact, p, 0,
-                                                  erts_backtrace_depth, 1),
-                        args);
-            hp += 2;
-            erts_factory_close(&hfact);
+            erts_factory_tmp_init(&hfact, NULL, 0, ERTS_ALC_T_TMP);
+            stacktrace = erts_build_stacktrace(&hfact, p, 0,
+                                               erts_backtrace_depth, 1);
+            hp = erts_produce_heap(&hfact, 2*(alive ? 9 : 8), 0);
+            args = CONS(hp, stacktrace, args); hp += 2;
             args = CONS(hp, msg, args); hp += 2;
             args = CONS(hp, make_small((p)->sig_inq.len), args); hp += 2;
             args = CONS(hp, am_true, args); hp += 2;
@@ -3758,9 +3756,10 @@ reached_max_heap_size(Process *p, Uint total_heap_size,
                 args = CONS(hp, erts_this_node->sysname, args); hp += 2;
             }
             args = CONS(hp, p->common.id, args); hp += 2;
+            ASSERT(hp == hfact.hp);
 
             erts_send_error_term_to_logger(p->group_leader, dsbufp, args);
-            erts_free(ERTS_ALC_T_TMP, o_hp);
+            erts_factory_close(&hfact);
         }
 
         if (IS_TRACED_FL(p, F_TRACE_GC))
-- 
2.35.3

openSUSE Build Service is sponsored by