diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-04-21 11:53:34 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-04-21 11:53:34 +0100 |
commit | 325aadbf2c598a172a1aaa0e083677bd06c8451e (patch) | |
tree | 8e09e4b8433899e01562afaea3123d867941d49b | |
parent | 39b1994c263c8751cfc2b5b28c001838d34aab44 (diff) | |
download | psycopg2-325aadbf2c598a172a1aaa0e083677bd06c8451e.tar.gz |
Check return code of pthread_mutex_initfix-901
Close #901
-rw-r--r-- | psycopg/connection_type.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 9d7e1ff..f472c4b 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -1349,7 +1349,7 @@ exit: static int connection_setup(connectionObject *self, const char *dsn, long int async) { - int res = -1; + int rv = -1; Dprintf("connection_setup: init connection object at %p, " "async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T, @@ -1373,19 +1373,21 @@ connection_setup(connectionObject *self, const char *dsn, long int async) /* other fields have been zeroed by tp_alloc */ - pthread_mutex_init(&(self->lock), NULL); + if (0 != pthread_mutex_init(&(self->lock), NULL)) { + PyErr_SetString(InternalError, "lock initialization failed"); + goto exit; + } if (conn_connect(self, async) != 0) { Dprintf("connection_init: FAILED"); goto exit; } - else { - Dprintf("connection_setup: good connection object at %p, refcnt = " - FORMAT_CODE_PY_SSIZE_T, - self, Py_REFCNT(self) - ); - res = 0; - } + + rv = 0; + + Dprintf("connection_setup: good connection object at %p, refcnt = " + FORMAT_CODE_PY_SSIZE_T, + self, Py_REFCNT(self)); exit: /* here we obfuscate the password even if there was a connection error */ @@ -1395,7 +1397,7 @@ exit: obscure_password(self); PyErr_Restore(ptype, pvalue, ptb); } - return res; + return rv; } |