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: ctypes: Memory leak at malloc_closure.c
Type: resource usage Stage:
Components: ctypes Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: John_Snow, brett.cannon, vstinner
Priority: normal Keywords:

Created on 2016-03-02 21:59 by John_Snow, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg261138 - (view) Author: John Snow (John_Snow) Date: 2016-03-02 21:59
malloc_closere.c holds a static list of items: free_list.
The items are being allocated in the more_core method using VirtualAlloc / mmap. However they never get released.

Here is the allocation code:

#ifdef MS_WIN32
    item = (ITEM *)VirtualAlloc(NULL,
                                           count * sizeof(ITEM),
                                           MEM_COMMIT,
                                           PAGE_EXECUTE_READWRITE);
    if (item == NULL)
        return;
#else
    item = (ITEM *)mmap(NULL,
                        count * sizeof(ITEM),
                        PROT_READ | PROT_WRITE | PROT_EXEC,
                        MAP_PRIVATE | MAP_ANONYMOUS,
                        -1,
                        0);
    if (item == (void *)MAP_FAILED)
        return;
#endif
msg261139 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-02 22:09
> malloc_closere.c

We are talking about Modules/_ctypes/malloc_closure.c.

> The items are being allocated in the more_core method using VirtualAlloc / mmap. However they never get released.

The allocation is only done once. I'm not sure that it can be called a leak. Calling the function 1,000 times will not allocate more memory.
msg261171 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-03-03 17:11
As Victor pointed out, it's a cache so it's not meant to free its initially allocated memory but to reuse it.

Closing this as "not a bug".
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70661
2016-03-03 17:11:21brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg261171

resolution: not a bug
2016-03-02 22:09:45vstinnersetnosy: + vstinner
title: Memory leak at malloc_closure.c -> ctypes: Memory leak at malloc_closure.c
messages: + msg261139

versions: + Python 3.5, Python 3.6
2016-03-02 21:59:56John_Snowcreate