[freetds] SQLDisconnect memory leak?

James K. Lowden jklowden at schemamania.org
Mon May 24 18:18:55 EDT 2004


[redirected to the list]

Begin forwarded message:

Date: Mon, 24 May 2004 16:26:08 +0800
From: "wangjiangui" <wangjiangui at mail.newtonecorp.com>
To: <freetds-owner at lists.ibiblio.org>
Subject: help

i met a very big problem.
i use the UnixODBC2.2.8 and Freetds0.61 to access
the MSSQL.
however,the function SQLConnect(maybe the SQLDisconnect) leads to the
memory leak.

So how can i solve this problem.
thank you.



the follow is my test program:

int db_open()
{
        SQLHENV henv;
        SQLHDBC hdbc;
        SQLRETURN               retcode;

        SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv );
        SQLSetEnvAttr( henv, SQL_ATTR_ODBC_VERSION,(void *)SQL_OV_ODBC3 ,
0 );
        SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc );

        /* Specify the ODBC Cursor Library is always used then connect. */
        retcode = SQLConnect( hdbc, (SQLCHAR *)"test",SQL_NTS,(SQLCHAR
*)"sa",SQL_NTS,(SQLCHAR *)"newtone", SQL
_NTS );
        if (!SQL_SUCCEEDED(retcode) || !SQL_SUCCEEDED(retcode)){
                SQLFreeHandle( SQL_HANDLE_DBC, hdbc );
                SQLFreeHandle( SQL_HANDLE_ENV, henv );
                printf("SQLConnect error  %d error.\n",retcode);
                return 0;
        }
        retcode = SQLDisconnect( hdbc );
        if (!SQL_SUCCEEDED(retcode) || !SQL_SUCCEEDED(retcode)){
                printf("SQLDisConnect error  %d error.\n",retcode);
        }
        if (!SQL_SUCCEEDED(retcode) || !SQL_SUCCEEDED(retcode)){
                printf("SQLDisConnect error  %d error.\n",retcode);
        }
        SQLFreeHandle( SQL_HANDLE_DBC, hdbc );
        if (!SQL_SUCCEEDED(retcode) || !SQL_SUCCEEDED(retcode)){
                printf("SQLFree hdbc error  %d error.\n",retcode);
        }
        SQLFreeHandle( SQL_HANDLE_ENV, henv );
        if (!SQL_SUCCEEDED(retcode) || !SQL_SUCCEEDED(retcode)){
                printf("SQLFree henv error  %d error.\n",retcode);
        }
        printf("SQLFree over.........\n");
        return 1;
}

int main()
{
        while(1){
               
printf("*********************************************.\n");
               
printf("*********************************************.\n");
               
printf("*********************************************.\n");
                struct timeval    time_val = {0};
                time_val.tv_sec  = 0;
                time_val.tv_usec = 500000;
                select(0, NULL, NULL, NULL, &time_val);
                db_open();
        }
        return 0;
}




More information about the FreeTDS mailing list