mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Fixed copyfile refcount in copy_expert
In case of early error, jumping to exit would have decref'd the borrowed reference to file. Issue spotted by Dave Malcolm, thanks!
This commit is contained in:
parent
b6e710b0fc
commit
679af4a975
|
@ -1505,14 +1505,15 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
self->copyfile = file;
|
self->copyfile = file;
|
||||||
|
|
||||||
/* At this point, the SQL statement must be str, not unicode */
|
/* At this point, the SQL statement must be str, not unicode */
|
||||||
if (pq_execute(self, Bytes_AS_STRING(sql), 0) != 1) { goto exit; }
|
if (pq_execute(self, Bytes_AS_STRING(sql), 0) == 1) {
|
||||||
|
|
||||||
res = Py_None;
|
res = Py_None;
|
||||||
Py_INCREF(res);
|
Py_INCREF(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
self->copyfile = NULL;
|
||||||
|
Py_DECREF(file);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
self->copyfile = NULL;
|
|
||||||
Py_XDECREF(file);
|
|
||||||
Py_XDECREF(sql);
|
Py_XDECREF(sql);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -244,6 +244,15 @@ class CopyTests(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(ntests, len(string.ascii_letters))
|
self.assertEqual(ntests, len(string.ascii_letters))
|
||||||
|
|
||||||
|
def test_copy_expert_file_refcount(self):
|
||||||
|
class Whatever(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
f = Whatever()
|
||||||
|
curs = self.conn.cursor()
|
||||||
|
self.assertRaises(TypeError,
|
||||||
|
curs.copy_expert, 'COPY tcopy (data) FROM STDIN', f)
|
||||||
|
|
||||||
decorate_all_tests(CopyTests, skip_if_green)
|
decorate_all_tests(CopyTests, skip_if_green)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user