summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-01-22 18:16:01 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-01-22 19:40:42 +0000
commite9c476266c07821c2f5a3ceed1d6a8e7f6ae82c7 (patch)
tree9d066f43b0aadf0cc09a46d0fb7244648ec48be2
parenteab5d5d93f7122937ced3c8dc81707e2f7bfc919 (diff)
downloadpsycopg2-e9c476266c07821c2f5a3ceed1d6a8e7f6ae82c7.tar.gz
Decrement the refcount of temporary objects in module init failed
We are going to die anyway, but let's do it in style.
-rw-r--r--psycopg/psycopgmodule.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 60b5758..dbe1699 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -719,6 +719,7 @@ RAISES_NEG
static int
add_module_constants(PyObject *module)
{
+ PyObject *tmp;
Dprintf("psycopgmodule: initializing module constants");
if (0 > PyModule_AddStringConstant(module,
@@ -734,16 +735,25 @@ add_module_constants(PyObject *module)
{ return -1; }
if (0 > PyModule_AddObject(module,
- "apilevel", Text_FromUTF8(APILEVEL)))
- { return -1; }
+ "apilevel", tmp = Text_FromUTF8(APILEVEL)))
+ {
+ Py_XDECREF(tmp);
+ return -1;
+ }
if (0 > PyModule_AddObject(module,
- "threadsafety", PyInt_FromLong(THREADSAFETY)))
- { return -1; }
+ "threadsafety", tmp = PyInt_FromLong(THREADSAFETY)))
+ {
+ Py_XDECREF(tmp);
+ return -1;
+ }
if (0 > PyModule_AddObject(module,
- "paramstyle", Text_FromUTF8(PARAMSTYLE)))
- { return -1; }
+ "paramstyle", tmp = Text_FromUTF8(PARAMSTYLE)))
+ {
+ Py_XDECREF(tmp);
+ return -1;
+ }
if (0 > PyModule_AddIntMacro(module, REPLICATION_PHYSICAL)) { return -1; }
if (0 > PyModule_AddIntMacro(module, REPLICATION_LOGICAL)) { return -1; }