Skip to content

Commit 762e76c

Browse files
peterzhu2118k0kubun
authored andcommitted
RUBY_FREE_AT_EXIT does not work when error in -r
[Bug #21173] When loading a file using the command line -r, it is processed before RUBY_FREE_AT_EXIT is checked. So if the loaded file raises an error, it will cause memory to not be freed with RUBY_FREE_AT_EXIT. For example `ruby -rtest.rb -e ""` will report a large amount of memory leaks if `test.rb` raises.
1 parent e15a904 commit 762e76c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ruby.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,18 +3166,18 @@ ruby_process_options(int argc, char **argv)
31663166
ruby_init_setproctitle(argc, argv);
31673167
#endif
31683168

3169+
if (getenv("RUBY_FREE_AT_EXIT")) {
3170+
rb_free_at_exit = true;
3171+
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, "Free at exit is experimental and may be unstable");
3172+
}
3173+
31693174
iseq = process_options(argc, argv, cmdline_options_init(&opt));
31703175

31713176
if (opt.crash_report && *opt.crash_report) {
31723177
void ruby_set_crash_report(const char *template);
31733178
ruby_set_crash_report(opt.crash_report);
31743179
}
31753180

3176-
if (getenv("RUBY_FREE_AT_EXIT")) {
3177-
rb_free_at_exit = true;
3178-
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, "Free at exit is experimental and may be unstable");
3179-
}
3180-
31813181
return (void*)(struct RData*)iseq;
31823182
}
31833183

0 commit comments

Comments
 (0)