File: _mysql.c
Function: _mysql_ConnectionObject_Initialize
Error: memory leak: ob_refcnt of new ref from (unknown) _mysql_Exception is 1 too high
528 static int
529 _mysql_ConnectionObject_Initialize(
530 	_mysql_ConnectionObject *self,
531 	PyObject *args,
532 	PyObject *kwargs)
533 {
534 	MYSQL *conn = NULL;
535 	PyObject *conv = NULL;
536 	PyObject *ssl = NULL;
537 #if HAVE_OPENSSL
538 	char *key = NULL, *cert = NULL, *ca = NULL,
539 		*capath = NULL, *cipher = NULL;
540 #endif
541 	char *host = NULL, *user = NULL, *passwd = NULL,
542 		*db = NULL, *unix_socket = NULL;
543 	unsigned int port = 0;
544 	unsigned int client_flag = 0;
545 	static char *kwlist[] = { "host", "user", "passwd", "db", "port",
546 				  "unix_socket", "conv",
547 				  "connect_timeout", "compress",
548 				  "named_pipe", "init_command",
549 				  "read_default_file", "read_default_group",
550 				  "client_flag", "ssl",
551 				  "local_infile",
552 #ifdef HAVE_MYSQL_OPT_TIMEOUTS
553 				  "read_timeout",
554 				  "write_timeout",
555 #endif
556 				  NULL } ;
557 	int connect_timeout = 0;
558 #ifdef HAVE_MYSQL_OPT_TIMEOUTS
559 	int read_timeout = 0;
560 	int write_timeout = 0;
561 #endif
562 	int compress = -1, named_pipe = -1, local_infile = -1;
563 	char *init_command=NULL,
564 	     *read_default_file=NULL,
565 	     *read_default_group=NULL;
566 	
567 	self->converter = NULL;
568 	self->open = 0;
569 	check_server_init(-1);
when considering range: -0x80000000 <= value <= -1
taking False path
570 
571 	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
when PyArg_ParseTupleAndKeywords() succeeds
taking False path
572 #ifdef HAVE_MYSQL_OPT_TIMEOUTS
573 					 "|ssssisOiiisssiOiii:connect",
574 #else
575 					 "|ssssisOiiisssiOi:connect",
576 #endif
577 					 kwlist,
578 					 &host, &user, &passwd, &db,
579 					 &port, &unix_socket, &conv,
580 					 &connect_timeout,
581 					 &compress, &named_pipe,
582 					 &init_command, &read_default_file,
583 					 &read_default_group,
584 					 &client_flag, &ssl,
585 		     &local_infile
586 #ifdef HAVE_MYSQL_OPT_TIMEOUTS
587 		     , &read_timeout
588 		     , &write_timeout
589 #endif
590 	))
591 		return -1;
592 
593 #define _stringsuck(d,t,s) {t=PyMapping_GetItemString(s,#d);\
594 	if(t){d=get_string(t);Py_DECREF(t);}\
595 	PyErr_Clear();}
596 
597 	if (ssl) {
taking True path
598 #if HAVE_OPENSSL
599 		PyObject *value = NULL;
600 		_stringsuck(ca, value, ssl);
when PyMapping_GetItemString() succeeds
taking True path
when taking True path
calling PyErr_Clear()
601 		_stringsuck(capath, value, ssl);
when PyMapping_GetItemString() succeeds
taking True path
when taking True path
calling PyErr_Clear()
602 		_stringsuck(cert, value, ssl);
when PyMapping_GetItemString() succeeds
taking True path
when taking True path
calling PyErr_Clear()
603 		_stringsuck(key, value, ssl);
when PyMapping_GetItemString() succeeds
taking True path
when taking True path
calling PyErr_Clear()
604 		_stringsuck(cipher, value, ssl);
when PyMapping_GetItemString() succeeds
taking True path
when taking True path
calling PyErr_Clear()
605 #else
606 		PyErr_SetString(_mysql_NotSupportedError,
607 				"client library does not have SSL support");
608 		return -1;
609 #endif
610 	}
611 
612 	Py_BEGIN_ALLOW_THREADS ;
releasing the GIL by calling PyEval_SaveThread()
613 	conn = mysql_init(&(self->connection));
614 	if (connect_timeout) {
when considering range: -0x80000000 <= value <= -1
taking True path
615 		unsigned int timeout = connect_timeout;
616 		mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT, 
617 				(char *)&timeout);
618 	}
619 #ifdef HAVE_MYSQL_OPT_TIMEOUTS
620 	if (read_timeout) {
when considering range: -0x80000000 <= value <= -1
taking True path
621 		unsigned int timeout = read_timeout;
622 		mysql_options(&(self->connection), MYSQL_OPT_READ_TIMEOUT,
623 				(char *)&timeout);
624 	}
625 	if (write_timeout) {
when considering range: -0x80000000 <= value <= -1
taking True path
626 		unsigned int timeout = write_timeout;
627 		mysql_options(&(self->connection), MYSQL_OPT_WRITE_TIMEOUT,
628 				(char *)&timeout);
629 	}
630 #endif
631 	if (compress != -1) {
when considering range: -0x80000000 <= value <= -2
taking True path
632 		mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0);
633 		client_flag |= CLIENT_COMPRESS;
634 	}
635 	if (named_pipe != -1)
when considering range: -0x80000000 <= value <= -2
taking True path
636 		mysql_options(&(self->connection), MYSQL_OPT_NAMED_PIPE, 0);
637 	if (init_command != NULL)
when treating unknown const char * from _mysql.c:571 as non-NULL
taking True path
638 		mysql_options(&(self->connection), MYSQL_INIT_COMMAND, init_command);
639 	if (read_default_file != NULL)
when treating unknown const char * from _mysql.c:571 as NULL
taking False path
640 		mysql_options(&(self->connection), MYSQL_READ_DEFAULT_FILE, read_default_file);
641 	if (read_default_group != NULL)
when treating unknown const char * from _mysql.c:571 as non-NULL
taking True path
642 		mysql_options(&(self->connection), MYSQL_READ_DEFAULT_GROUP, read_default_group);
643 
644 	if (local_infile != -1)
when considering range: 0 <= value <= 0x7fffffff
taking True path
645 		mysql_options(&(self->connection), MYSQL_OPT_LOCAL_INFILE, (char *) &local_infile);
646 
647 #if HAVE_OPENSSL
648 	if (ssl)
taking True path
649 		mysql_ssl_set(&(self->connection),
650 			      key, cert, ca, capath, cipher);
651 #endif
652 
653 	conn = mysql_real_connect(&(self->connection), host, user, passwd, db,
654 				  port, unix_socket, client_flag);
655 
656 	Py_END_ALLOW_THREADS ;
reacquiring the GIL by calling PyEval_RestoreThread()
657 
658 	if (!conn) {
when treating unknown struct MYSQL * from _mysql.c:653 as NULL
taking True path
659 		_mysql_Exception(self);
when _mysql_Exception() succeeds
new ref from (unknown) _mysql_Exception was allocated at: 		_mysql_Exception(self);
ob_refcnt is now refs: 1 owned
660 		return -1;
661 	}
662 
663 	/* Internal references to python-land objects */
664 	if (!conv)
665 		conv = PyDict_New();
666 	else
667 		Py_INCREF(conv);
668 
669 	if (!conv)
670 		return -1;
671 	self->converter = conv;
672 
673 	/*
674 	  PyType_GenericAlloc() automatically sets up GC allocation and
675 	  tracking for GC objects, at least in 2.2.1, so it does not need to
676 	  be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(),
677 	  however.
678 	*/
679 	self->open = 1;
680 	return 0;
681 }