Skip to content

Commit 6bad47a

Browse files
committed
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 bb91c30 commit 6bad47a

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
@@ -3131,18 +3131,18 @@ ruby_process_options(int argc, char **argv)
31313131
ruby_init_setproctitle(argc, argv);
31323132
#endif
31333133

3134+
if (getenv("RUBY_FREE_AT_EXIT")) {
3135+
rb_free_at_exit = true;
3136+
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, "Free at exit is experimental and may be unstable");
3137+
}
3138+
31343139
iseq = process_options(argc, argv, cmdline_options_init(&opt));
31353140

31363141
if (opt.crash_report && *opt.crash_report) {
31373142
void ruby_set_crash_report(const char *template);
31383143
ruby_set_crash_report(opt.crash_report);
31393144
}
31403145

3141-
if (getenv("RUBY_FREE_AT_EXIT")) {
3142-
rb_free_at_exit = true;
3143-
rb_category_warn(RB_WARN_CATEGORY_EXPERIMENTAL, "Free at exit is experimental and may be unstable");
3144-
}
3145-
31463146
return (void*)(struct RData*)iseq;
31473147
}
31483148

0 commit comments

Comments
 (0)