From: Antoine Pitrou Date: Thu, 5 Apr 2012 12:07:52 +0000 (+0200) Subject: Issue #14505: Fix file descriptor leak when deallocating file objects created with... X-Git-Tag: v2.7.4rc1~921 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02a380105d4cd31219d2dc468f277688973ec2bd;p=python Issue #14505: Fix file descriptor leak when deallocating file objects created with PyFile_FromString(). --- diff --git a/Misc/NEWS b/Misc/NEWS index 8593a10b1c..330477e655 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ What's New in Python 2.7.4 Core and Builtins ----------------- +- Issue #14505: Fix file descriptor leak when deallocating file objects + created with PyFile_FromString(). + - Issue #14474: Save and restore exception state in thread.start_new_thread() while writing error message if the thread leaves a unhandled exception. diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 050e239c4f..1d8142e17c 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -493,9 +493,10 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *)) PyObject * PyFile_FromString(char *name, char *mode) { + extern int fclose(FILE *); PyFileObject *f; - f = (PyFileObject *)PyFile_FromFile((FILE *)NULL, name, mode, NULL); + f = (PyFileObject *)PyFile_FromFile((FILE *)NULL, name, mode, fclose); if (f != NULL) { if (open_the_file(f, name, mode) == NULL) { Py_DECREF(f);