Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b948553

Browse filesBrowse files
benjaminpmethane
authored andcommitted
simplify memory management of the conv dictionary
In ResultObject_Initialize, always borrow the conv dictionary from the caller. This simplifies the code, removes an allocation, and fixes ref leaks in error cases.
1 parent 73ccdcd commit b948553
Copy full SHA for b948553

File tree

Expand file treeCollapse file tree

1 file changed

+1
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-13
lines changed

‎_mysql.c

Copy file name to clipboardExpand all lines: _mysql.c
+1-13Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,6 @@ _mysql_ResultObject_Initialize(
363363
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|iO", kwlist,
364364
&_mysql_ConnectionObject_Type, &conn, &use, &conv))
365365
return -1;
366-
if (!conv) {
367-
if (!(conv = PyDict_New()))
368-
return -1;
369-
}
370-
else
371-
Py_INCREF(conv);
372366

373367
self->conn = (PyObject *) conn;
374368
Py_INCREF(conn);
@@ -387,29 +381,25 @@ _mysql_ResultObject_Initialize(
387381
return -1;
388382
}
389383
self->converter = PyTuple_New(0);
390-
Py_DECREF(conv);
391384
return 0;
392385
}
393386
n = mysql_num_fields(result);
394387
self->nfields = n;
395388
if (!(self->converter = PyTuple_New(n))) {
396-
Py_DECREF(conv);
397389
return -1;
398390
}
399391
fields = mysql_fetch_fields(result);
400392
for (i=0; i<n; i++) {
401393
PyObject *tmp, *fun;
402394
tmp = PyInt_FromLong((long) fields[i].type);
403395
if (!tmp) {
404-
Py_DECREF(conv);
405396
return -1;
406397
}
407-
fun = PyObject_GetItem(conv, tmp);
398+
fun = conv ? PyObject_GetItem(conv, tmp) : NULL;
408399
Py_DECREF(tmp);
409400
if (!fun) {
410401
if (PyErr_Occurred()) {
411402
if (!PyErr_ExceptionMatches(PyExc_KeyError)) {
412-
Py_DECREF(conv);
413403
return -1;
414404
}
415405
PyErr_Clear();
@@ -428,7 +418,6 @@ _mysql_ResultObject_Initialize(
428418
PyObject *t = PySequence_GetItem(fun, j);
429419
if (!t) {
430420
Py_DECREF(fun);
431-
Py_DECREF(conv);
432421
return -1;
433422
}
434423
if (PyTuple_Check(t) && PyTuple_GET_SIZE(t) == 2) {
@@ -463,7 +452,6 @@ _mysql_ResultObject_Initialize(
463452
PyTuple_SET_ITEM(self->converter, i, fun);
464453
}
465454

466-
Py_DECREF(conv);
467455
return 0;
468456
}
469457

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.