Saturday, February 25, 2012

ODBC Memory Leak

We are using ODBC connection pooling with SQL Server 2000 v5 on Win 2000 v5
sp4.

Each time we get a connection, SQLConnect, we see the memory usage go
up, about 52K. When we return the connection to the pool,
SQLDisconnect, and after the time that the connection remains in pool
expires we see the memory usage drop by about 28K.

Our basic steps for a select are:
SQLAllocHandle(SQL_HANDLE_DBC, hGblEnv, &hdbc);
SQLSetConnectAttr(hdbc, SQL_ATTR_LOGIN_TIMEOUT,
(SQLPOINTER)lLoginTimeOut, 0);
SQLSetConnectAttr(hdbc, SQL_ATTR_ACCESS_MODE,
(SQLPOINTER)SQL_MODE_READ_ONLY, SQL_IS_POINTER);
SQLConnect(hdbc,(SQLCHAR *)szDatabase, SQL_NTS,
(SQLCHAR *)szUserId, SQL_NTS,
(SQLCHAR *)szPassword, SQL_NTS);
SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
// Build the select statement
SQLExecDirect(hstmt, (SQLCHAR * )pszSQLStmt, strlen(pszSQLStmt));
SQLFetch(hstmt);
SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);

Same memory leak occurs in DB2, but that's another forum.[posted and mailed, please reply in news]

M. Oakley (moakley@.acrosoft.com) writes:
> We are using ODBC connection pooling with SQL Server 2000 v5 on Win 2000
> v5 sp4.
> Each time we get a connection, SQLConnect, we see the memory usage go
> up, about 52K. When we return the connection to the pool,
> SQLDisconnect, and after the time that the connection remains in pool
> expires we see the memory usage drop by about 28K.
> Our basic steps for a select are:
> SQLAllocHandle(SQL_HANDLE_DBC, hGblEnv, &hdbc);
> SQLSetConnectAttr(hdbc, SQL_ATTR_LOGIN_TIMEOUT,
> (SQLPOINTER)lLoginTimeOut, 0);
> SQLSetConnectAttr(hdbc, SQL_ATTR_ACCESS_MODE,
> (SQLPOINTER)SQL_MODE_READ_ONLY, SQL_IS_POINTER);
> SQLConnect(hdbc,(SQLCHAR *)szDatabase, SQL_NTS,
> (SQLCHAR *)szUserId, SQL_NTS,
> (SQLCHAR *)szPassword, SQL_NTS);
> SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
> // Build the select statement
> SQLExecDirect(hstmt, (SQLCHAR * )pszSQLStmt, strlen(pszSQLStmt));
> SQLFetch(hstmt);
> SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
> SQLDisconnect(hdbc);

There is a known issue with a memory leak in ODBC, described in
http://support.microsoft.com/?id=814410. This fix is included in SP3a,
but *not* in SP3, so you might want to investigate if this could be
the same.

However, I'm not completely sure that this is the same leak. I did get
a repro for the original leak, which lead to the fix in 814410, but not
programming ODBC much myself, I don't remember the details.

In any case, in case SP3a does not resolve the problem, could you compose
a complete repro that demonstrates the problem? That is a program that
I can compile and run? In such case, I should be able to bring it up
with Microsoft.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

No comments:

Post a Comment