summaryrefslogtreecommitdiff
path: root/src/winrand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/winrand.c')
-rw-r--r--src/winrand.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/winrand.c b/src/winrand.c
index d06b242..4200fbc 100644
--- a/src/winrand.c
+++ b/src/winrand.c
@@ -271,19 +271,19 @@ PyInit_winrandom()
initwinrandom()
#endif
{
- PyObject *m;
-#ifdef IS_PY3K
+ PyObject *m = NULL;
+
if (PyType_Ready(&WRtype) < 0)
- return NULL;
- /* Initialize the module */
- m = PyModule_Create(&moduledef);
- if (m == NULL)
- return NULL;
+ goto errout;
+
+ /* Initialize the module */
+#ifdef IS_PY3K
+ m = PyModule_Create(&moduledef);
#else
- if (PyType_Ready(&WRtype) < 0)
- return NULL;
m = Py_InitModule("winrandom", WR_mod_methods);
#endif
+ if (m == NULL)
+ goto errout;
/* define Windows CSP Provider Types */
#ifdef PROV_RSA_FULL
@@ -359,12 +359,26 @@ initwinrandom()
PyModule_AddStringConstant(m, "INTEL_DEF_PROV", INTEL_DEF_PROV);
#endif
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module winrandom");
+out:
+ /* Final error check */
+ if (m == NULL && !PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "can't initialize module");
+ goto errout;
+ }
+
+ /* Free local objects here */
+ /* Return */
#ifdef IS_PY3K
return m;
+#else
+ return;
#endif
+
+errout:
+ /* Free the module and other global objects here */
+ Py_CLEAR(m);
+ goto out;
}
/*