Skip to content

Commit 9445ecd

Browse files
authored
Merge pull request #263 from IntelPython/fix-ufuncs-module-leak
Avoid leaking module object on numpy C-API import failure
2 parents 79dc27c + 34f00db commit 9445ecd

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414
* Fixed an over-decref of the borrowed module dictionary reference on the module initialization error path [gh-264](https://github.com/IntelPython/mkl_umath/pull/264)
15+
* Fixed a leak of the module object when the NumPy C-API import fails during module initialization [gh-263](https://github.com/IntelPython/mkl_umath/pull/263)
1516

1617
## [0.5.0] - 2026-08-06
1718

‎mkl_umath/src/ufuncsmodule.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ PyMODINIT_FUNC PyInit__ufuncs(void)
4040
PyObject *m;
4141
PyObject *d;
4242

43+
/* NumPy C-API init macros: they `return NULL;` on failure, so call them
44+
* before PyModule_Create() to avoid leaking the module on early return. */
45+
import_array();
46+
import_umath();
47+
4348
m = PyModule_Create(&_ufuncs_module);
4449
if (m == NULL)
4550
return NULL;
@@ -50,9 +55,6 @@ PyMODINIT_FUNC PyInit__ufuncs(void)
5055
return NULL;
5156
}
5257

53-
import_array();
54-
import_umath();
55-
5658
if (InitOperators(d) < 0) {
5759
/* d is a borrowed reference from PyModule_GetDict; do not decref it. */
5860
Py_XDECREF(m);

0 commit comments

Comments
 (0)