* psycopg/typecast.c (typecast_from_c): fix up some reference

leaks.  This leak affected a bounded set of objects, so doesn't
	account for any gradual leaks.
This commit is contained in:
James Henstridge 2008-03-25 23:21:00 +00:00
parent af1478feb9
commit e848585b90
2 changed files with 20 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2008-03-26 James Henstridge <james@jamesh.id.au>
* psycopg/typecast.c (typecast_from_c): fix up some reference
leaks. This leak affected a bounded set of objects, so doesn't
account for any gradual leaks.
2008-03-19 James Henstridge <james@jamesh.id.au> 2008-03-19 James Henstridge <james@jamesh.id.au>
* psycopg/connection_int.c (conn_notice_callback): don't leak * psycopg/connection_int.c (conn_notice_callback): don't leak

View File

@ -523,8 +523,8 @@ typecast_from_python(PyObject *self, PyObject *args, PyObject *keywds)
PyObject * PyObject *
typecast_from_c(typecastObject_initlist *type, PyObject *dict) typecast_from_c(typecastObject_initlist *type, PyObject *dict)
{ {
PyObject *tuple, *base = NULL; PyObject *name = NULL, *values = NULL, *base = NULL;
typecastObject *obj; typecastObject *obj = NULL;
Py_ssize_t i, len = 0; Py_ssize_t i, len = 0;
/* before doing anything else we look for the base */ /* before doing anything else we look for the base */
@ -533,27 +533,32 @@ typecast_from_c(typecastObject_initlist *type, PyObject *dict)
base = PyDict_GetItemString(dict, type->base); base = PyDict_GetItemString(dict, type->base);
if (!base) { if (!base) {
PyErr_Format(Error, "typecast base not found: %s", type->base); PyErr_Format(Error, "typecast base not found: %s", type->base);
return NULL; goto end;
} }
} }
name = PyString_FromString(type->name);
if (!name) goto end;
while (type->values[len] != 0) len++; while (type->values[len] != 0) len++;
tuple = PyTuple_New(len); values = PyTuple_New(len);
if (!tuple) return NULL; if (!values) goto end;
for (i = 0; i < len ; i++) { for (i = 0; i < len ; i++) {
PyTuple_SET_ITEM(tuple, i, PyInt_FromLong(type->values[i])); PyTuple_SET_ITEM(values, i, PyInt_FromLong(type->values[i]));
} }
obj = (typecastObject *)typecast_new(name, values, NULL, base);
obj = (typecastObject *)
typecast_new(PyString_FromString(type->name), tuple, NULL, base);
if (obj) { if (obj) {
obj->ccast = type->cast; obj->ccast = type->cast;
obj->pcast = NULL; obj->pcast = NULL;
} }
end:
Py_XDECREF(values);
Py_XDECREF(name);
return (PyObject *)obj; return (PyObject *)obj;
} }