From 91d240160f34817bcbac7062e5270753d250c913 Mon Sep 17 00:00:00 2001 From: Byron Clark Date: Sun, 4 Apr 2021 17:32:28 -0600 Subject: [PATCH] Fixes #1252 - Increment refcount on provided parameters. When parsing an object (`O`) with `PyArg_ParseTuple` and friends, the provided object is set in the appropiate field, but the refcount is not incremented. Reference: https://docs.python.org/3/c-api/arg.html#other-objects. Use `Py_XINCREF` to increment the refcount on any objects that may have been passed into this function. `Py_XINCREF` performs a NULL check internally and only increments the refcounter on non-NULL objects. --- psycopg/column_type.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/psycopg/column_type.c b/psycopg/column_type.c index b7007065..e85509c8 100644 --- a/psycopg/column_type.c +++ b/psycopg/column_type.c @@ -108,6 +108,16 @@ column_init(columnObject *self, PyObject *args, PyObject *kwargs) return -1; } + Py_XINCREF(self->name); + Py_XINCREF(self->type_code); + Py_XINCREF(self->display_size); + Py_XINCREF(self->internal_size); + Py_XINCREF(self->precision); + Py_XINCREF(self->scale); + Py_XINCREF(self->null_ok); + Py_XINCREF(self->table_oid); + Py_XINCREF(self->table_column); + return 0; }