I have a piece of code that connects to such a MySQL database (not directly from the code, so there may be typos):
m_connectionHandler = mysql_init(NULL);
if (m_connectionHandler == NULL)
{
return;
}
MYSQL *tmp = mysql_real_connect(m_connectionHandler,
m_hostname,
m_username,
m_password,
m_dbName,
m_port,
NULL,
m_flags);
if (tmp == NULL)
{
mysql_close(m_connectionHandler);
return;
}
My question is: if mysql_close(in the second case, if tmp == NULL), in the case when it mysql_real_connectreturns NULL, is it required, or if mysql_real_connectthe connection handler frees me for an error?
The documentation states that what you get from mysql_initshould be freed mysql_close, but there are signs that it is already freed mysql_real_connectupon failure.
Can anyone shed some light on this for me?
source
share