From c645b7d135e6de341f5452aeb3771e2b6779dc80 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Jul 2018 07:20:11 +0000 Subject: reduce stack usage from file names Ruby source locations can be extremely long and use excessive stack space. Move it off stack for the temporary key lookup to reduce the likelyhood of stack overflows. No need to use TSD (which is stored on stack with GCC anyways); as we have GVL at that point. --- ext/mwrap/mwrap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index 6109070..d08ebf0 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -291,6 +291,7 @@ static struct src_loc *update_stats_rcu(size_t size, uintptr_t caller) const char *ptr = rb_source_location_cstr(&line); size_t len; size_t int_size = INT2STR_MAX; + static char buf[PATH_MAX + INT2STR_MAX + sizeof(*k) + 2]; generation = rb_gc_count(); @@ -298,7 +299,7 @@ static struct src_loc *update_stats_rcu(size_t size, uintptr_t caller) /* avoid vsnprintf or anything which could call malloc here: */ len = strlen(ptr); - k = alloca(sizeof(*k) + len + 1 + int_size + 1); + k = (void *)buf; k->total = size; dst = mempcpy(k->k, ptr, len); *dst++ = ':'; -- cgit v1.2.3-24-ge0c7