[unixODBC-dev] ini caching leak

John Fuller jfuller at wernervas.com
Fri Sep 3 21:05:20 BST 2004


I was running 2.2.8 and noticed that if I repeatedly attempt connection
to a database that is down, I was leaking memory from SQLConnect \
so I changed the Makefile in odbcinst to -DDISABLE_INI_CACHING
and the leak stopped....

Here's a snippet of the code in my test loop.

/***/

    SQLHENV         m_hEnv= SQL_NULL_HENV;
    SQLHDBC         m_hDBC= SQL_NULL_HDBC;
    SQLHSTMT       m_hStmt= SQL_NULL_HSTMT;
    RETCODE         nRC;

    nRC = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_hEnv );

    // When we set the environment this way, we start leaking
    // when the database is down
    SQLPOINTER ver= (SQLPOINTER)SQL_OV_ODBC3;
    char*      c= getenv("CDATABASE_ODBC_VERSION");
    if (c) { ver= (SQLPOINTER)atoi(c); }
    nRC = SQLSetEnvAttr
    (m_hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)ver, SQL_IS_INTEGER);

    // Allocate an ODBC connection handle and connect.
    nRC = SQLAllocHandle( SQL_HANDLE_DBC, m_hEnv, &m_hDBC );

    nRC = SQLConnect( m_hDBC, (UCHAR*)m_strDSN, (SWORD)strlen(m_strDSN),
                      (UCHAR*)m_strUID, (SWORD)strlen(m_strUID),
                      (UCHAR*)m_strPWD, (SWORD)strlen(m_strPWD) );

    // of course if we don't have a connection the next line would fail, 
but
    // just to keep it simple...
    SQLDisconnect(m_hDBC);
    SQLFreeHandle( SQL_HANDLE_DBC, m_hDBC );
    SQLFreeHandle( SQL_HANDLE_ENV, m_hEnv );

/***/




More information about the unixODBC-dev mailing list