mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-12 15:20:32 +03:00
Check connection type in lobject init
Fixes ticket #187. Conflicts: NEWS
This commit is contained in:
parent
2840643924
commit
ff341077e0
2
NEWS
2
NEWS
|
@ -8,6 +8,8 @@ What's new in psycopg 2.4.7
|
||||||
Distribute project on Python 3 (ticket #153).
|
Distribute project on Python 3 (ticket #153).
|
||||||
- Meaningful connection errors report a meaningful message, thanks to
|
- Meaningful connection errors report a meaningful message, thanks to
|
||||||
Alexey Borzenkov (:ticket:`#173`).
|
Alexey Borzenkov (:ticket:`#173`).
|
||||||
|
- Manually creating `lobject` with the wrong parameter doesn't segfault
|
||||||
|
(:ticket:`#187`).
|
||||||
|
|
||||||
|
|
||||||
What's new in psycopg 2.4.6
|
What's new in psycopg 2.4.6
|
||||||
|
|
|
@ -359,10 +359,12 @@ lobject_dealloc(PyObject* obj)
|
||||||
{
|
{
|
||||||
lobjectObject *self = (lobjectObject *)obj;
|
lobjectObject *self = (lobjectObject *)obj;
|
||||||
|
|
||||||
|
if (self->conn) { /* if not, init failed */
|
||||||
if (lobject_close(self) < 0)
|
if (lobject_close(self) < 0)
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
Py_XDECREF((PyObject*)self->conn);
|
Py_XDECREF((PyObject*)self->conn);
|
||||||
PyMem_Free(self->smode);
|
PyMem_Free(self->smode);
|
||||||
|
}
|
||||||
|
|
||||||
Dprintf("lobject_dealloc: deleted lobject object at %p, refcnt = "
|
Dprintf("lobject_dealloc: deleted lobject object at %p, refcnt = "
|
||||||
FORMAT_CODE_PY_SSIZE_T, obj, Py_REFCNT(obj));
|
FORMAT_CODE_PY_SSIZE_T, obj, Py_REFCNT(obj));
|
||||||
|
@ -376,10 +378,11 @@ lobject_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
||||||
int oid = (int)InvalidOid, new_oid = (int)InvalidOid;
|
int oid = (int)InvalidOid, new_oid = (int)InvalidOid;
|
||||||
const char *smode = "";
|
const char *smode = "";
|
||||||
const char *new_file = NULL;
|
const char *new_file = NULL;
|
||||||
PyObject *conn;
|
PyObject *conn = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|iziz",
|
if (!PyArg_ParseTuple(args, "O!|iziz",
|
||||||
&conn, &oid, &smode, &new_oid, &new_file))
|
&connectionType, &conn,
|
||||||
|
&oid, &smode, &new_oid, &new_file))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return lobject_setup((lobjectObject *)obj,
|
return lobject_setup((lobjectObject *)obj,
|
||||||
|
|
|
@ -85,6 +85,10 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
||||||
self.assertNotEqual(lo, None)
|
self.assertNotEqual(lo, None)
|
||||||
self.assertEqual(lo.mode[0], "w")
|
self.assertEqual(lo.mode[0], "w")
|
||||||
|
|
||||||
|
def test_connection_needed(self):
|
||||||
|
self.assertRaises(TypeError,
|
||||||
|
psycopg2.extensions.lobject, [])
|
||||||
|
|
||||||
def test_open_non_existent(self):
|
def test_open_non_existent(self):
|
||||||
# By creating then removing a large object, we get an Oid that
|
# By creating then removing a large object, we get an Oid that
|
||||||
# should be unused.
|
# should be unused.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user