[issue28200] Windows: path_converter() leaks memory for Unicode filenames

STINNER Victor report at bugs.python.org
Mon Sep 19 04:44:12 EDT 2016


STINNER Victor added the comment:

Steve Dower added the comment:
> It's not clear to me that Py_UNICODE is guaranteed to be wchar_t for all time, that's all. If it is, go ahead.

Right now, it's the case and path_converter() leaks memory, so I
proposed a simple and obvious fix :-)

On Windows, it makes sense to continue to use the UTF-16 encoded
string cached in Unicode objects, because this conversion is common,
and it's convenient to not have to release the memory explicitly. The
side effect is that we may waste memory in some cases.

> Otherwise the path_t object has the ability to clean up after itself, so perhaps it should be used here?

Maybe, but I'm not interested to write a more complex patch for
Windows :-) Try to just call PyMem_Free(path->wide) (do nothing it's
NULL).

The advantage of the old code (and my patch) is to only convert a
filename once to UTF-16 and then use the cached result.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28200>
_______________________________________


More information about the Python-bugs-list mailing list