[#114774] [Ruby master Feature#19884] Make Safe Navigation Operator work on classes — "p8 (Petrik de Heus) via ruby-core" <ruby-core@...>
Issue #19884 has been reported by p8 (Petrik de Heus).
13 messages
2023/09/15
[ruby-core:114834] [Ruby master Bug#19624] Backticks - IO object leakage
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-09-20 11:57:24 UTC
List:
ruby-core #114834
Issue #19624 has been updated by nobu (Nobuyoshi Nakada).
Is this OK?
```diff
diff --git a/io.c b/io.c
index 712dce3ceb8..48cdc5b9a7a 100644
--- a/io.c
+++ b/io.c
@@ -5574,12 +5574,9 @@ clear_codeconv(rb_io_t *fptr)
clear_writeconv(fptr);
}
=20
-void
-rb_io_fptr_finalize_internal(void *ptr)
+static void
+rb_io_fptr_cleanup_all(rb_io_t *fptr)
{
- rb_io_t *fptr =3D ptr;
-
- if (!ptr) return;
fptr->pathv =3D Qnil;
if (0 <=3D fptr->fd)
rb_io_fptr_cleanup(fptr, TRUE);
@@ -5587,7 +5584,14 @@ rb_io_fptr_finalize_internal(void *ptr)
free_io_buffer(&fptr->rbuf);
free_io_buffer(&fptr->wbuf);
clear_codeconv(fptr);
- free(fptr);
+}
+
+void
+rb_io_fptr_finalize_internal(void *ptr)
+{
+ if (!ptr) return;
+ rb_io_fptr_cleanup_all(ptr);
+ free(ptr);
}
=20
#undef rb_io_fptr_finalize
@@ -10467,11 +10471,9 @@ rb_f_backquote(VALUE obj, VALUE str)
if (NIL_P(port)) return rb_str_new(0,0);
=20
GetOpenFile(port, fptr);
- rb_obj_hide(port);
result =3D read_all(fptr, remain_size(fptr), Qnil);
rb_io_close(port);
- RFILE(port)->fptr =3D NULL;
- rb_io_fptr_finalize(fptr);
+ rb_io_fptr_cleanup_all(fptr);
RB_GC_GUARD(port);
=20
return result;
```
----------------------------------------
Bug #19624: Backticks - IO object leakage
https://bugs.ruby-lang.org/issues/19624#change-104678
* Author: pineman (Jo=E3o Pinheiro)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Hi,
This code works on ruby 3.0.6:
```ruby
`echo`
ObjectSpace.each_object(IO) do |io|
if ![STDIN, STDOUT, STDERR].include?(io)
io.close
end
end
```
but raises `IOError` on 3.2.2:
```
minimal-repro-case.rb:8:in `close': uninitialized stream (IOError)
```
I found it started failing on ruby 3.1.0 and after, on macOS and Linux.
This code is useful for closing unneeded IO objects in forked processes.
It looks like backticks is 'leaking' IO objects, waiting for GC, and it did=
n't used to before 3.1.0.
In ruby 3.1.0, inside `rb_f_backquote` in `io.c`, `rb_gc_force_recycle` was=
removed in favor of `RB_GC_GUARD` (commit `aeae6e2842e`). I wonder if this=
has something to do with the problem.
Is this code incorrect since ruby 3.1.0 or is it a bug in ruby?
Thanks.
---Files--------------------------------
minimal-repro-case.rb (109 Bytes)
--=20
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-c=
ore.ml.ruby-lang.org/