Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e64ef93

Browse files
committed
SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
A file-static "threads" dict mapped thread IDs to Windows handles, but was never referenced, and entries never got removed. This gets rid of the YAGNI-dict entirely. Bugfix candidate.
1 parent 5e67cde commit e64ef93

2 files changed

Lines changed: 2 additions & 14 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ Rickard Westman
474474
Truida Wiedijk
475475
Gerry Wiener
476476
Bryce "Zooko" Wilcox-O'Hearn
477+
Gerald S. Williams
477478
Sue Williams
478479
Frank Willison
479480
Greg V. Wilson

Python/thread_nt.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11

22
/* This code implemented by [email protected] */
33
/* Fast NonRecursiveMutex support by Yakov Markovitch, [email protected] */
4+
/* Eliminated some memory leaks, [email protected] */
45

56
#include <windows.h>
67
#include <limits.h>
78
#include <process.h>
8-
#include <Python.h>
99

1010
typedef struct NRMUTEX {
1111
LONG owned ;
1212
DWORD thread_id ;
1313
HANDLE hevent ;
1414
} NRMUTEX, *PNRMUTEX ;
1515

16-
/* dictionary to correlate thread ids with the handle needed to terminate them*/
17-
static PyObject *threads = NULL;
18-
1916
typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ;
2017

2118
/* Sorry mate, but we haven't got InterlockedCompareExchange in Win95! */
@@ -138,17 +135,11 @@ void FreeNonRecursiveMutex(PNRMUTEX mutex)
138135

139136
long PyThread_get_thread_ident(void);
140137

141-
/*
142-
* Change all headers to pure ANSI as no one will use K&R style on an
143-
* NT
144-
*/
145-
146138
/*
147139
* Initialization of the C package, should not be needed.
148140
*/
149141
static void PyThread__init_thread(void)
150142
{
151-
threads = PyDict_New();
152143
}
153144

154145
/*
@@ -182,7 +173,6 @@ long PyThread_start_new_thread(void (*func)(void *), void *arg)
182173
int success = 0;
183174
callobj *obj;
184175
int id;
185-
PyObject *key, *val;
186176

187177
dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
188178
if (!initialized)
@@ -203,9 +193,6 @@ long PyThread_start_new_thread(void (*func)(void *), void *arg)
203193
/* wait for thread to initialize and retrieve id */
204194
WaitForSingleObject(obj->done, 5000); /* maybe INFINITE instead of 5000? */
205195
CloseHandle((HANDLE)obj->done);
206-
key = PyLong_FromLong(obj->id);
207-
val = PyLong_FromLong((long)rv);
208-
PyDict_SetItem(threads, key, val);
209196
id = obj->id;
210197
free(obj);
211198
return id;

0 commit comments

Comments
 (0)