about summary refs log tree commit homepage
path: root/ext/mwrap/mwrap.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-07-14 07:20:11 +0000
committerEric Wong <e@80x24.org>2018-07-16 19:34:32 +0000
commitc645b7d135e6de341f5452aeb3771e2b6779dc80 (patch)
tree0bc26d8ea29d9fd6c822d51c1fe8c95aff7ad211 /ext/mwrap/mwrap.c
parentd5650c7e56431cda2f59032698dfb5d462215efc (diff)
downloadmwrap-c645b7d135e6de341f5452aeb3771e2b6779dc80.tar.gz
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.
Diffstat (limited to 'ext/mwrap/mwrap.c')
-rw-r--r--ext/mwrap/mwrap.c3
1 files changed, 2 insertions, 1 deletions
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++ = ':';