[Python-Dev] Segfault

Ronald Oussoren ronaldoussoren at mac.com
Tue Aug 21 10:50:46 CEST 2007


Please create a patch for this in the tracker to ensure that this patch doesn't get lost.

Ronald
 
On Tuesday, August 21, 2007, at 10:47AM, "Hrvoje Nik?i?" <hrvoje.niksic at avl.com> wrote:
>On Mon, 2007-08-20 at 20:27 +0200, Maciej Fijalkowski wrote:
>> import thread
>> 
>> while 1:
>>     f = open("/tmp/dupa", "w")
>>     thread.start_new_thread(f.close, ())
>>     f.close()
>
>file_close inadvertently allows fclose to be called twice on the same
>stdio file.  This patch should fix the problem:
>
>Python-2.5.1/Objects/fileobject.c
>--- Python-2.5.1.orig/Objects/fileobject.c	2007-01-23 14:54:30.000000000 +0100
>+++ Python-2.5.1/Objects/fileobject.c	2007-08-21 10:04:18.000000000 +0200
>@@ -440,13 +440,14 @@
> {
> 	int sts = 0;
> 	if (f->f_fp != NULL) {
>+		FILE *fp = f->f_fp;
>+		f->f_fp = NULL;
> 		if (f->f_close != NULL) {
> 			Py_BEGIN_ALLOW_THREADS
> 			errno = 0;
>-			sts = (*f->f_close)(f->f_fp);
>+			sts = (*f->f_close)(fp);
> 			Py_END_ALLOW_THREADS
> 		}
>-		f->f_fp = NULL;
> 	}
> 	PyMem_Free(f->f_setbuf);
> 	f->f_setbuf = NULL;
>
>
>_______________________________________________
>Python-Dev mailing list
>Python-Dev at python.org
>http://mail.python.org/mailman/listinfo/python-dev
>Unsubscribe: http://mail.python.org/mailman/options/python-dev/ronaldoussoren%40mac.com
>
>


More information about the Python-Dev mailing list