diff options
| author | nagachika <nagachika@ruby-lang.org> | 2024-12-21 13:31:11 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2024-12-21 13:31:11 +0900 |
| commit | 1d57924d693534b10699a375cb8400e57a67031c (patch) | |
| tree | 2c4cb693e8dbd3028c7df0171f10da12baff9980 | |
| parent | 3110d5c8abf8f710de42989fbc35870287a12f75 (diff) | |
merge revision(s) a1758fbd7fe7406601b0eb1617752db59b83586a:
Crash when malloc during GC
This feature was introduced in commit 2ccf6e5, but I realized that
using rb_warn is a bad idea because it allocates objects, which causes
a different crash ("object allocation during garbage collection phase").
We should just hard crash here instead.
| -rw-r--r-- | gc.c | 24 | ||||
| -rw-r--r-- | version.h | 2 |
2 files changed, 13 insertions, 13 deletions
@@ -12318,18 +12318,23 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) } \ } while (0) +static void +check_malloc_not_in_gc(rb_objspace_t *objspace, const char *msg) +{ + if (UNLIKELY(malloc_during_gc_p(objspace))) { + dont_gc_on(); + during_gc = false; + rb_bug("Cannot %s during GC", msg); + } +} + /* these shouldn't be called directly. * objspace_* functions do not check allocation size. */ static void * objspace_xmalloc0(rb_objspace_t *objspace, size_t size) { - if (UNLIKELY(malloc_during_gc_p(objspace))) { - rb_warn("malloc during GC detected, this could cause crashes if it triggers another GC"); -#if RGENGC_CHECK_MODE || RUBY_DEBUG - rb_bug("Cannot malloc during GC"); -#endif - } + check_malloc_not_in_gc(objspace, "malloc"); void *mem; @@ -12348,12 +12353,7 @@ xmalloc2_size(const size_t count, const size_t elsize) static void * objspace_xrealloc(rb_objspace_t *objspace, void *ptr, size_t new_size, size_t old_size) { - if (UNLIKELY(malloc_during_gc_p(objspace))) { - rb_warn("realloc during GC detected, this could cause crashes if it triggers another GC"); -#if RGENGC_CHECK_MODE || RUBY_DEBUG - rb_bug("Cannot realloc during GC"); -#endif - } + check_malloc_not_in_gc(objspace, "realloc"); void *mem; @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 245 +#define RUBY_PATCHLEVEL 246 #include "ruby/version.h" #include "ruby/internal/abi.h" |
