File: _mysql.c
Function: _mysql_ResultObject_Initialize
Error: memory leak: ob_refcnt of PyTupleObject is 1 too high
382 static int
383 _mysql_ResultObject_Initialize(
384 	_mysql_ResultObject *self,
385 	PyObject *args,
386 	PyObject *kwargs)
387 {
388 	static char *kwlist[] = {"connection", "use", "converter", NULL};
389 	MYSQL_RES *result; 
390 	_mysql_ConnectionObject *conn=NULL;
391 	int use=0; 
392 	PyObject *conv=NULL;
393 	int n, i;
394 	MYSQL_FIELD *fields;
395 
396 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist,
when PyArg_ParseTupleAndKeywords() succeeds
taking False path
397 					  &conn, &use, &conv))
398 		return -1;
399 	if (!conv) {
taking False path
400 		if (!(conv = PyDict_New()))
401 			return -1;
402 	}
403 	else
404 		Py_INCREF(conv);
405 
406 	self->conn = (PyObject *) conn;
407 	Py_INCREF(conn);
408 	self->use = use;
409 	Py_BEGIN_ALLOW_THREADS ;
releasing the GIL by calling PyEval_SaveThread()
410 	if (use)
when considering range: -0x80000000 <= value <= -1
taking True path
411 		result = mysql_use_result(&(conn->connection));
412 	else
413 		result = mysql_store_result(&(conn->connection));
414 	self->result = result;
415 	Py_END_ALLOW_THREADS ;
reacquiring the GIL by calling PyEval_RestoreThread()
416 	if (!result) {
when treating unknown struct MYSQL_RES * from _mysql.c:411 as non-NULL
taking False path
417 		if (mysql_field_count(&(conn->connection)) > 0) {
418 		    _mysql_Exception(conn);
419 		    return -1;
420 		}
421 		self->converter = PyTuple_New(0);
422 		Py_DECREF(conv);
423 		return 0;
424 	}
425 	n = mysql_num_fields(result);
426 	self->nfields = n;
427 	if (!(self->converter = PyTuple_New(n))) {
when PyTuple_New() succeeds
taking False path
PyTupleObject was allocated at: 	if (!(self->converter = PyTuple_New(n))) {
ob_refcnt is now refs: 1 owned
428 		Py_DECREF(conv);
429 		return -1;
430 	}
431 	fields = mysql_fetch_fields(result);
432 	for (i=0; i<n; i++) {
when considering range: 1 <= n <= 0xffffffff
taking True path
when considering n == (unsigned int)1 from _mysql.c:425
taking False path
433 		PyObject *tmp, *fun;
434 		tmp = PyInt_FromLong((long) fields[i].type);
when treating unknown struct MYSQL_FIELD * from _mysql.c:434 as non-NULL
when PyInt_FromLong() succeeds
435 		if (!tmp) {
taking False path
436 			Py_DECREF(conv);
437 			return -1;
438 		}
439 		fun = PyObject_GetItem(conv, tmp);
when PyObject_GetItem() succeeds
440 		Py_DECREF(tmp);
when taking True path
441 		if (!fun) {
taking False path
442 			if (PyErr_Occurred()) {
443 				if (!PyErr_ExceptionMatches(PyExc_KeyError)) {
444 					Py_DECREF(conv);
445 					return -1;
446 				}
447 				PyErr_Clear();
448 			}
449 			fun = Py_None;
450 			Py_INCREF(Py_None);
451 		}
452 		else if (PySequence_Check(fun)) {
when considering range: -0x80000000 <= value <= -1
taking True path
453 			int j, n2=PySequence_Size(fun);
when PySequence_Size() succeeds
454 			PyObject *fun2=NULL;
455 			for (j=0; j<n2; j++) {
when considering range: 1 <= n2 <= 0x7fffffff
taking True path
when considering n2 == (int)1 from _mysql.c:453
taking False path
456 				PyObject *t = PySequence_GetItem(fun, j);
when PySequence_GetItem() succeeds
457 				if (!t) {
taking False path
458 					Py_DECREF(fun);
459 					Py_DECREF(conv);
460 					return -1;
461 				}
462 				if (PyTuple_Check(t) && PyTuple_GET_SIZE(t) == 2) {
when considering range: 1 <= value <= 0x4000000
taking True path
when considering value == (Py_ssize_t)2 from _mysql.c:462
taking True path
463 					long mask, flags;
464 					PyObject *pmask=NULL;
465 					pmask = PyTuple_GET_ITEM(t, 0);
466 					fun2 = PyTuple_GET_ITEM(t, 1);
467 					Py_XINCREF(fun2);
when treating unknown struct PyObject * from _mysql.c:466 as non-NULL
taking False path
468 					if (PyInt_Check(pmask)) {
when treating unknown struct PyObject * from _mysql.c:465 as non-NULL
when treating unknown struct _typeobject * from _mysql.c:468 as non-NULL
when considering range: 1 <= value <= 0x800000
taking True path
469 						mask = PyInt_AS_LONG(pmask);
470 						flags = fields[i].flags;
when treating unknown struct MYSQL_FIELD * from _mysql.c:470 as non-NULL
471 						if (fields[i].charsetnr != 63) { /* maaagic */
when treating unknown struct MYSQL_FIELD * from _mysql.c:471 as non-NULL
when considering range: 0 <= value <= 62
taking True path
472 							flags &= ~BINARY_FLAG;
473 						}
474 						if (mask & flags) {
when considering value == (long int)0 from _mysql.c:474
taking False path
475 							Py_DECREF(t);
476 							break;
477 						}
478 						else {
479 							fun2 = NULL;
480 						}
481 					} else {
482 						Py_DECREF(t);
483 						break;
484 					}
485 				}
486 				Py_DECREF(t);
when taking True path
487 			}
488 			if (!fun2) {
taking True path
489 				fun2 = Py_None;
490 				Py_INCREF(fun2);
491 			}
492 			Py_DECREF(fun);
when taking True path
493 			fun = fun2;
494 		}
495 		PyTuple_SET_ITEM(self->converter, i, fun);
496 	}
497 
498 	Py_DECREF(conv);
when considering range: -0x8000000000000000 <= value <= -1
taking True path
499 	return 0;
500 }