Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Memory leak when the module created by MOD_DEF is not decreased on failure (static analyzer report) #8091

Open
Snape3058 opened this issue May 22, 2022 · 2 comments
Labels

Comments

@Snape3058
Copy link

Macro MOD_DEF will create a module PyObject with a new reference returned and assigned to the first argument.

ob = PyModule_Create(&moduledef); }

The following places invoke the macro but do not decrease the refcnt of the module PyObject on failure.


Invoked here:

MOD_DEF(m, "_dispatcher", "No docs", ext_methods)

Function returns without decreasing the refcnt.
return MOD_ERROR_VAL;

Internal Report ID: 0dc3d1


Invoked here:

MOD_DEF(m, "_dynfunc", "No docs", ext_methods)

Function returns without decreasing the refcnt.
return MOD_ERROR_VAL;

Internal Report ID: 235f50


Invoked here:

MOD_DEF(m, "_helperlib", "No docs", ext_methods)

Function returns in macro import_array without decreasing the refcnt.
import_array();

Internal Report ID: f3d5d2


Invoked here:

MOD_DEF(m, "_nrt_python", "No docs", ext_methods)

Function returns in macro import_array without decreasing the refcnt.

Internal Report ID: 724a48


Invoked here:

MOD_DEF(m, "_box", "No docs", ext_methods)

Function returns without decreasing the refcnt.
return MOD_ERROR_VAL;

Internal Report ID: 31f898


Invoked here:

MOD_DEF(module, "mviewbuf", "No docs", core_methods)

Function returns without decreasing the refcnt.
return MOD_ERROR_VAL;

Internal Report ID: f68b83


Invoked here:

MOD_DEF(m, "_internal", "No docs",

Function returns without decreasing the refcnt.
return MOD_ERROR_VAL;

Internal Report ID: ed7b7c

@stuartarchibald
Copy link
Contributor

Thanks for the report.

Macro MOD_DEF will create a module PyObject with a new reference returned and assigned to the first argument.

ob = PyModule_Create(&moduledef); }

The following places invoke the macro but do not decrease the refcnt of the module PyObject on failure.

Invoked here:

MOD_DEF(m, "_dispatcher", "No docs", ext_methods)

Function returns without decreasing the refcnt.

return MOD_ERROR_VAL;

Internal Report ID: 0dc3d1

On inspection, this analysis looks valid.

Invoked here:

MOD_DEF(m, "_dynfunc", "No docs", ext_methods)

Function returns without decreasing the refcnt.

return MOD_ERROR_VAL;

Internal Report ID: 235f50

On inspection, this analysis looks valid.

Invoked here:

MOD_DEF(m, "_helperlib", "No docs", ext_methods)

Function returns in macro import_array without decreasing the refcnt.

import_array();

Internal Report ID: f3d5d2

On inspection, this analysis looks valid. Note that the macro import_array comes from NumPy, it contains the return NULL.

Invoked here:

MOD_DEF(m, "_nrt_python", "No docs", ext_methods)

Function returns in macro import_array without decreasing the refcnt.

Internal Report ID: 724a48

On inspection, this analysis looks valid. Note that the macro import_array comes from NumPy, it contains the return NULL.

Invoked here:

MOD_DEF(m, "_box", "No docs", ext_methods)

Function returns without decreasing the refcnt.

return MOD_ERROR_VAL;

Internal Report ID: 31f898

On inspection, this analysis looks valid.

Invoked here:

MOD_DEF(module, "mviewbuf", "No docs", core_methods)

Function returns without decreasing the refcnt.

return MOD_ERROR_VAL;

Internal Report ID: f68b83

On inspection, this analysis looks valid.

Invoked here:

MOD_DEF(m, "_internal", "No docs",

Function returns without decreasing the refcnt.

return MOD_ERROR_VAL;

Internal Report ID: ed7b7c

On inspection, this analysis looks valid. There's also further places in that MOD_INIT(_internal) which have the same issue. Does the tool being used pick these up, or just the first case?

@Snape3058
Copy link
Author

For the return NULL in import_array, we are discussing a solution in SciPy by moving the invocation of import_array to the very beginning of the function.
You can have a try on this solution to see whether it works for this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants