[New-bugs-announce] [issue17051] Memory leak in os.path.isdir under Windows
Robert Xiao
report at bugs.python.org
Sun Jan 27 10:10:56 CET 2013
New submission from Robert Xiao:
[From http://stackoverflow.com/questions/12648737/huge-memory-leak-in-repeated-os-path-isdir-calls]
os.path.isdir() leaks memory under Windows in Python 2.7. The core cause is this snippet:
Modules/posixmodule.c:4226:
if (!PyArg_ParseTuple(args, "et:_isdir",
Py_FileSystemDefaultEncoding, &path))
return NULL;
attributes = GetFileAttributesA(path);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;
check:
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
The buffer returned by the "et" ParseTuple format must be freed after use. Since it isn't freed, we get a memory leak here.
Patch:
--- a/Modules/posixmodule.c Mon Apr 09 19:04:04 2012 -0400
+++ b/Modules/posixmodule.c Sun Jan 27 04:10:34 2013 -0500
@@ -4226,6 +4226,7 @@
return NULL;
attributes = GetFileAttributesA(path);
+ PyMem_Free(path);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;
----------
components: Library (Lib)
messages: 180754
nosy: nneonneo
priority: normal
severity: normal
status: open
title: Memory leak in os.path.isdir under Windows
type: resource usage
versions: Python 2.6, Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17051>
_______________________________________
More information about the New-bugs-announce
mailing list