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/x509.c b/src/crypto/x509.c
index e089d40..b230c3d 100644
--- a/src/crypto/x509.c
+++ b/src/crypto/x509.c
@@ -852,6 +852,11 @@
return 0;
}
+ /* PyModule_AddObject steals a reference. We need crypto_X509_Type to
+ * still be ours at least until the second PyModule_AddObject call
+ * below.
+ */
+ Py_INCREF((PyObject *)&crypto_X509_Type);
if (PyModule_AddObject(module, "X509", (PyObject *)&crypto_X509_Type) != 0) {
return 0;
}