From c05a2c6a50bb57655165cf95279d5501226ce369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Malo?= Date: Wed, 3 Oct 2012 13:17:35 -0400 Subject: [PATCH] Patch 3/4: _mysql.c reference counting and exception issues This patch fixes a reference leak and improves the error handling in the converter mapping code. Rather accidentially it also drops the cleanup: label and the gotos ;) https://sourceforge.net/p/mysql-python/patches/79/ --- MySQLdb/_mysql.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 63e990f..b222663 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -407,8 +407,13 @@ _mysql_ResultObject_Initialize( if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, &conn, &use, &conv)) return -1; - if (!conv) conv = PyDict_New(); - if (!conv) return -1; + if (!conv) { + if (!(conv = PyDict_New())) + return -1; + } + else + Py_INCREF(conv); + self->conn = (PyObject *) conn; Py_INCREF(conn); self->use = use; @@ -425,31 +430,47 @@ _mysql_ResultObject_Initialize( return -1; } self->converter = PyTuple_New(0); + Py_DECREF(conv); return 0; } n = mysql_num_fields(result); self->nfields = n; - if (!(self->converter = PyTuple_New(n))) return -1; + if (!(self->converter = PyTuple_New(n))) { + Py_DECREF(conv); + return -1; + } fields = mysql_fetch_fields(result); for (i=0; iconverter, i, fun); } + + Py_DECREF(conv); return 0; }