pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedMemory Leak when freeing statement
3+ messages / 2 participants
[nested] [flat]
* Memory Leak when freeing statement
@ 2005-03-24 18:52 Kelly Burkhart <kelly@tradebotsystems.com>
0 siblings, 1 reply; 3+ messages in thread
From: Kelly Burkhart @ 2005-03-24 18:52 UTC (permalink / raw)
To: pgsql-odbc
I have found a memory leak when freeing a statement handle which has had
parameters bound in psqlodbc-08.00.0101. I was able to eliminate the
leak by adding:
SC_free_params(self, STMT_FREE_PARAMS_ALL);
to line 330 of statement.c in the SC_Destructor method. I'm not
familiar enough with the code to know if this is a sensible fix.
-K
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Memory Leak when freeing statement
@ 2005-03-30 18:06 Peter Eisentraut <peter_e@gmx.net>
parent: Kelly Burkhart <kelly@tradebotsystems.com>
0 siblings, 1 reply; 3+ messages in thread
From: Peter Eisentraut @ 2005-03-30 18:06 UTC (permalink / raw)
To: Kelly Burkhart <kelly@tradebotsystems.com>; +Cc: pgsql-odbc
Kelly Burkhart wrote:
> I have found a memory leak when freeing a statement handle which has
> had parameters bound in psqlodbc-08.00.0101. I was able to eliminate
> the leak by adding:
>
> SC_free_params(self, STMT_FREE_PARAMS_ALL);
>
> to line 330 of statement.c in the SC_Destructor method. I'm not
> familiar enough with the code to know if this is a sensible fix.
Can you provide an example program that shows the memory leak?
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Memory Leak when freeing statement
@ 2005-03-30 20:39 Kelly Burkhart <kelly@tradebotsystems.com>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 3+ messages in thread
From: Kelly Burkhart @ 2005-03-30 20:39 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: pgsql-odbc
On Wed, 2005-03-30 at 12:06, Peter Eisentraut wrote:
> Kelly Burkhart wrote:
> > I have found a memory leak when freeing a statement handle which has
> > had parameters bound in psqlodbc-08.00.0101. I was able to eliminate
> > the leak by adding:
> >
> > SC_free_params(self, STMT_FREE_PARAMS_ALL);
> >
> > to line 330 of statement.c in the SC_Destructor method. I'm not
> > familiar enough with the code to know if this is a sensible fix.
>
> Can you provide an example program that shows the memory leak?
In the attached program, each query iteration leaks 12 bytes per input
variable. Output variables have no effect.
-K
Attachments:
tst_odbcleak.cpp (text/x-c++, 3.5K) download
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
#define CONN_DB ((SQLCHAR*)"<DB>")
#define CONN_USR ((SQLCHAR*)"<USR>")
#define CONN_PWD ((SQLCHAR*)"<PWD>")
static void ckSts( RETCODE sts, const char *method ) {
if (sts != SQL_SUCCESS && sts != SQL_SUCCESS_WITH_INFO) {
fprintf( stderr, "%s failed with status: %d\n", method, sts );
exit(1);
}
}
static void query( HDBC hdbc );
int main()
{
HENV henv = SQL_NULL_HENV;
HDBC hdbc = SQL_NULL_HDBC;
int32_t version = SQL_OV_ODBC3;
RETCODE status;
status = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv );
ckSts( status, "SQLAllocHandle(ENV)" );
status = SQLSetEnvAttr( henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER *)version, 0 );
ckSts( status, "SQLSetEnvAttr" );
status = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc );
ckSts( status, "SQLAllocHandle(DBC)" );
status = SQLConnect( hdbc, CONN_DB, SQL_NTS, CONN_USR, SQL_NTS, CONN_PWD, SQL_NTS );
ckSts( status, "SQLConnect" );
{
int idx;
for( idx=0; idx<1000; ++idx )
query( hdbc );
}
SQLDisconnect( hdbc );
SQLFreeHandle( SQL_HANDLE_DBC, hdbc );
SQLFreeHandle( SQL_HANDLE_ENV, henv );
return 0;
}
static void query( HDBC hdbc )
{
HSTMT hstmt;
/* Each time I add an input variable I lose 12 bytes per iteration */
char input0[1024];
SDWORD iind0 = sizeof(input0);
char input1[1024];
SDWORD iind1 = sizeof(input1);
char input2[1024];
SDWORD iind2 = sizeof(input1);
/* Adding output vars doesn't affect leak */
char output0[1024];
SDWORD oind0;
char output1[1024];
SDWORD oind1;
char statement[1024];
RETCODE status;
/* strcpy( statement, "select 'foo', 'bar' where 'abcdefg' = ?" ); /**/
/* strcpy( statement, "select 'foo', 'bar' where 'abcdefg' = ? and 'abcdefg' = ?" ); /**/
strcpy( statement, "select 'foo', 'bar' where 'abcdefg' = ? and 'abcdefg' = ? and 'abcdefg' = ?" ); /**/
strcpy( input0, "abcdefg" );
strcpy( input1, "abcdefg" );
strcpy( input2, "abcdefg" );
SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt );
status = SQLPrepare( hstmt, (unsigned char *)statement, SQL_NTS );
ckSts( status, "SQLPrepare" );
status = SQLBindParameter( hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
sizeof(input0), 0, (UCHAR *)input0, 0, (SDWORD *)&iind0 );
ckSts( status, "SQLBindParameter" );
status = SQLBindParameter( hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
sizeof(input1), 0, (UCHAR *)input1, 0, (SDWORD *)&iind1 );
ckSts( status, "SQLBindParameter" );
status = SQLBindParameter( hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
sizeof(input2), 0, (UCHAR *)input2, 0, (SDWORD *)&iind2 );
ckSts( status, "SQLBindParameter" );
status = SQLBindCol( hstmt, 1, SQL_C_CHAR, (UCHAR *)output0, sizeof(output0), (SDWORD *)&oind0 );
ckSts( status, "SQLBindCol" );
status = SQLBindCol( hstmt, 2, SQL_C_CHAR, (UCHAR *)output1, sizeof(output1), (SDWORD *)&oind1 );
ckSts( status, "SQLBindCol" );
status = SQLExecute( hstmt );
ckSts( status, "SQLExecute" );
status = SQLFetch( hstmt );
ckSts( status, "SQLFetch" );
printf("Fetched \"%s\", \"%s\"\n", output0, output1 );
SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
}
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-03-30 20:39 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-24 18:52 Memory Leak when freeing statement Kelly Burkhart <kelly@tradebotsystems.com>
2005-03-30 18:06 ` Peter Eisentraut <peter_e@gmx.net>
2005-03-30 20:39 ` Kelly Burkhart <kelly@tradebotsystems.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox