Skip to Content.
Sympa Menu

freetds - RE: [freetds] ODBC memory leak?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: ZIGLIO Frediano <Frediano.Ziglio AT vodafoneomnitel.it>
  • To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] ODBC memory leak?
  • Date: Thu, 6 Mar 2003 15:56:44 +0100

>
> Hi again,
>
> I discovered a memory leak in the application I'm developing,
> and I think
> I may have traced the problem to either the Freetds ODBC driver or
> unixODBC. Of course, it's possible I'm not explicity freeing
> something
> that I should.
>
> Sample code that compiles on my RedHat 8 (x86) machine is attached
> (change the connection parameters in main() to try it out).
> Here's what
> I'm doing, in pseudocode:
>
> SQLAllocHandle(SQL_NULL_HANDLE,hEnv)
> SQLAllocHandle(hEnv,hDbc)
> SQLConnect(hDbc,...)
> Loop:
> SQLAllocHandle(hDbc,hStmt)
> SQLBindCol(hStmt,...)
> SQLExecDirect(hStmt,...)
> SQLFetch(hStmt) . . . .
> SQLFreeStmt(hStmt)
> SQLFreeHandle(hStmt)
> SQLDisconnect(hDbc)
> SQLFreeHandle(hDbc)
> SQLFreeHandle(hEnv)
>
> The inner loop seems to leave 8 k unfreed ever time it is run.
>
> To see the memory leak, run top or something alongside it and
> watch the
> process grow by 8 k per second.
>
> BTW my server is SQLServer 2000, and I'm using unixODBC 2.2.2.
>

I removed some leak today, but related to environment/connection, not
statement

Your code have some line wrong

Wrong
SQLFreeHandle(SQL_HANDLE_STMT, &hStmt);

Correct
SQLFreeHandle(SQL_HANDLE_STMT, hStmt);

You must pass handle, not a pointer to handle (handle are defined as void*,
so you didn't received errors... very bad odbc definition)

Also

erg = SQLConnect(hOdbc, ...
if ( erg != SQL_SUCCESS )
...

Should be changed to

erg = SQLConnect(hOdbc, ...
if (!SQL_SUCCEEDED(erg))
...

(cvs driver and ms one return SQL_SUCCESS_WITH_INFO)

bye
freddy77

=================================
"STRICTLY PERSONAL AND CONFIDENTIAL

This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.
The contents of this message that do not relate to the official business of
our company shall be understood as neither given nor endorsed by it."

=================================




Archive powered by MHonArc 2.6.24.

Top of Page