...
The idea is that if the srcfile is already open, then it
should be left
open; but if it is not open, it should be closed at the end.
open() on
an open srcfile is supposed to make no change to the srcfile, just
return the already open connection.
(It looks like the srcref stuff is not finished yet, as
there are other
problems, like print(parse(file)) not showing what it used to.)
This is an encoding problem, which looks easy to fix. I
think the leak
was caused by this: because of the encoding problem, the connections
got opened but open.srcfile aborted before completion, so
close.srcfile
didn't think the srcfile was open at all, and it left the
connections in
existence.
That incompletely opened connection may be why after doing
this test closeAllConnections crashed R because the ex_ptr
component of an Rconnection object was a nil pointer:
tf<-tempfile()
cat(file=tf, "1:10\nlog(log(pi))\n")
p<-parse(tf)
p
expression(<srcref: file "/tmp/RtmpazU79B/file327b23c6" chars 1:1 to 1:4>,
<srcref: file "/tmp/RtmpazU79B/file327b23c6" chars 2:1 to 2:12>)
attr(,"srcfile")
/tmp/RtmpazU79B/file327b23c6