This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients doko, pitrou, vstinner
Date 2012-04-05.10:30:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1333621813.52.0.0442623539335.issue14505@psf.upfronthosting.co.za>
In-reply-to
Content
> File descriptors opened by PyFile_FromString don't get closed
> when the reference count is decreased.

Correct, PyFile_FromString() doesn't close the file descriptor, even if you call its close() method. You have to call manually fclose(file->f_fp).

Or you can use PyFile_FromFile:

fp = fopen(name, mode);
if (fp == NULL) ...
obj = PyFile_FromFile(fp, name, mode, fclose);
if (obj == NULL) {
   /* no need to call fclose(fp) here, it's done by PyFile_FromFile() */
   ...
}
...
Py_DECREF(obj);

Would you like to write a patch for the documentation?
History
Date User Action Args
2012-04-05 10:30:13vstinnersetrecipients: + vstinner, doko, pitrou
2012-04-05 10:30:13vstinnersetmessageid: <1333621813.52.0.0442623539335.issue14505@psf.upfronthosting.co.za>
2012-04-05 10:30:12vstinnerlinkissue14505 messages
2012-04-05 10:30:12vstinnercreate