mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Check for memory errors in the connection init
This commit is contained in:
parent
7996333ee7
commit
d74f777339
|
@ -820,28 +820,31 @@ static int
|
||||||
connection_setup(connectionObject *self, const char *dsn, long int async)
|
connection_setup(connectionObject *self, const char *dsn, long int async)
|
||||||
{
|
{
|
||||||
char *pos;
|
char *pos;
|
||||||
int res;
|
int res = -1;
|
||||||
|
|
||||||
Dprintf("connection_setup: init connection object at %p, "
|
Dprintf("connection_setup: init connection object at %p, "
|
||||||
"async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
|
"async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
|
||||||
self, async, Py_REFCNT(self)
|
self, async, Py_REFCNT(self)
|
||||||
);
|
);
|
||||||
|
|
||||||
self->dsn = strdup(dsn);
|
if (!(self->dsn = strdup(dsn))) {
|
||||||
self->notice_list = PyList_New(0);
|
PyErr_NoMemory();
|
||||||
self->notifies = PyList_New(0);
|
goto exit;
|
||||||
|
}
|
||||||
|
if (!(self->notice_list = PyList_New(0))) { goto exit; }
|
||||||
|
if (!(self->notifies = PyList_New(0))) { goto exit; }
|
||||||
self->async = async;
|
self->async = async;
|
||||||
self->status = CONN_STATUS_SETUP;
|
self->status = CONN_STATUS_SETUP;
|
||||||
self->async_status = ASYNC_DONE;
|
self->async_status = ASYNC_DONE;
|
||||||
self->string_types = PyDict_New();
|
if (!(self->string_types = PyDict_New())) { goto exit; }
|
||||||
self->binary_types = PyDict_New();
|
if (!(self->binary_types = PyDict_New())) { goto exit; }
|
||||||
/* other fields have been zeroed by tp_alloc */
|
/* other fields have been zeroed by tp_alloc */
|
||||||
|
|
||||||
pthread_mutex_init(&(self->lock), NULL);
|
pthread_mutex_init(&(self->lock), NULL);
|
||||||
|
|
||||||
if (conn_connect(self, async) != 0) {
|
if (conn_connect(self, async) != 0) {
|
||||||
Dprintf("connection_init: FAILED");
|
Dprintf("connection_init: FAILED");
|
||||||
res = -1;
|
goto exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Dprintf("connection_setup: good connection object at %p, refcnt = "
|
Dprintf("connection_setup: good connection object at %p, refcnt = "
|
||||||
|
@ -858,6 +861,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
||||||
*pos = 'x';
|
*pos = 'x';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user