PyModule_AddObject steals a reference. Fix all of the double calls to it by adding a Py_INCREF. Also, some other assorted hacks which probably shouldn't be necessary but are at the moment.
diff --git a/src/crypto/pkey.c b/src/crypto/pkey.c
index 583a2a1..ab8363a 100644
--- a/src/crypto/pkey.c
+++ b/src/crypto/pkey.c
@@ -266,6 +266,9 @@
return 0;
}
+ /* PyModule_AddObject steals a reference.
+ */
+ Py_INCREF((PyObject *)&crypto_PKey_Type);
if (PyModule_AddObject(module, "PKey", (PyObject *)&crypto_PKey_Type) != 0) {
return 0;
}