New submission from intuited <[email protected]>:
Discovered when using the current Ubuntu 10.04 package of Python: 2.6.5-0ubuntu1
Reproducible with ::
outfile = open("tmpout", "w")
outfile.writelines(f() or "line" for f in (outfile.close,))
This problem is probably most likely to be encountered when using the
``fileinput`` module, because of the way it abstracts away the closing of
files. E.G.::
from fileinput import input
lines = input("tmpout", inplace=1)
first = lines.next()
from sys import stdout
stdout.writelines(lines)
Both of the above pieces of code cause Segmentation Faults.
It looks like in line 1779 of ``Objects/fileobject.c``, ``f->fp`` is being
passed to ``fwrite`` as 0. I guess this happens because no check is done after
the call to ``PyIter_Next`` on line 1730 to see if the file is still open.
I don't see this as a big issue, though it is annoying that it seemingly
prevents generators from being used with the `fileinput` module. Doing so
would be a bit awkward and hacky anyway though.
----------
components: IO
messages: 118877
nosy: intuited
priority: normal
severity: normal
status: open
title: Closing a file within its writelines method causes segfault
type: crash
versions: Python 2.6
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue10125>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com