diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-09-17 21:16:58 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-11-02 18:23:43 -0800 |
commit | 96d7c88819733eaaba892177a967d9e898b2b924 (patch) | |
tree | dcc519ccc95d8fdc5e1c912e4b704da38d26f8a0 /gv.c | |
parent | f4725fad1a6349bcfadca13ee4398f61799a29d0 (diff) | |
download | perl-96d7c88819733eaaba892177a967d9e898b2b924.tar.gz |
[perl #57512] Warnings for implicitly closed handles
If the implicit close() fails, warn about it, mentioning $! in the
message. This is a default warning in the io category.
We do this in two spots, sv_clear and gp_free. While sv_clear would
be sufficient to get the warning emitted, the warning won’t contain
the name of the handle when called from there, because lone IO thing-
ies are nameless. Doing it also when a GV’s glob pointer is freed--as
long as the IO thingy in there has a reference count of 1--allows the
name to be included in the message, because we still have the glob,
which is where the name is stored.
The result:
$ ./miniperl -Ilib -e 'open fh, ">/Volumes/Disk Image/foo"; print fh "x"x1000, "\n" for 1..50; undef *fh'
Warning: unable to close filehandle fh properly: No space left on device at -e line 1.
Diffstat (limited to 'gv.c')
-rw-r--r-- | gv.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -2515,6 +2515,16 @@ Perl_gp_free(pTHX_ GV *gv) (void)hv_deletehek(PL_stashcache, hvname_hek, G_DISCARD); SvREFCNT_dec(hv); } + if (io && SvREFCNT(io) == 1 && IoIFP(io) + && (IoTYPE(io) == IoTYPE_WRONLY || + IoTYPE(io) == IoTYPE_RDWR || + IoTYPE(io) == IoTYPE_APPEND) + && ckWARN_d(WARN_IO) + && IoIFP(io) != PerlIO_stdin() + && IoIFP(io) != PerlIO_stdout() + && IoIFP(io) != PerlIO_stderr() + && !(IoFLAGS(io) & IOf_FAKE_DIRP)) + io_close(io, gv, FALSE, TRUE); SvREFCNT_dec(io); SvREFCNT_dec(cv); SvREFCNT_dec(form); |