Commit 681567a
Avoid leaking module object on numpy C-API import failure
import_array() and import_umath() are macros that expand to `return NULL;`
on failure. When they were called after PyModule_Create(), a failing import
would return directly out of PyInit__ufuncs without releasing the module
object, leaking the strong reference created by PyModule_Create().
Move the imports before the module is created so there is no owned
reference to leak when an import fails.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 5202088 commit 681567a
1 file changed
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
0 commit comments