This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: winreg.c:Reg2Py() may leak memory (in unusual circumstances)
Type: resource usage Stage: resolved
Components: Windows Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stutzbach Nosy List: BreamoreBoy, Claudiu.Popa, stutzbach
Priority: low Keywords:

Created on 2010-07-07 17:52 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg109486 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-07-07 17:52
In Reg2Py() in winreg.c, in the REG_MULTI_SZ case, there's the following:

                wchar_t **str = (wchar_t **)malloc(sizeof(wchar_t *)*s);
                if (str == NULL)
                    return PyErr_NoMemory();

However, not all of the return paths after that point call free(str).

The leaking paths are pretty unusual, so I'm setting the priority to low.  The leaking paths occur when PyList_New returns NULL or if the registry entry contains more than INT_MAX characters.

Two other things I noticed and I'm not sure about:

Is INT_MAX really the maximum number of characters for a Python unicode string?

Should this be using PyMem functions instead of malloc/free?
msg220826 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-17 13:14
Can somebody answer the question about PyMem versus malloc/free functions.
msg237517 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2015-03-08 07:28
This was fixed a couple of months ago: https://hg.python.org/cpython/rev/07968254be96. Also, malloc was changed to PyMem_New a couple of weeks ago: https://hg.python.org/cpython/rev/036a2aceae93
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53437
2015-03-08 07:28:46Claudiu.Popasetstatus: open -> closed

nosy: + Claudiu.Popa
messages: + msg237517

resolution: fixed
stage: needs patch -> resolved
2014-06-17 18:57:36brian.curtinsetnosy: - brian.curtin
2014-06-17 13:14:28BreamoreBoysetnosy: + BreamoreBoy
messages: + msg220826
2010-07-07 18:20:26brian.curtinsetnosy: + brian.curtin
2010-07-07 17:52:44stutzbachcreate