pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Memory Leak ?
21+ messages / 3 participants
[nested] [flat]

* Memory Leak ?
@ 2006-06-08 09:01  zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-08 09:01 UTC (permalink / raw)
  To: pgsql-odbc

Hi,
  I have a C++ application for testing memory leak that connects to
PostgreSQL8.1.3 Database using psqlODBC 08.01.02.00 unicode driver.
I have found some memory leak with the windows performance tool.
I have tried to upgrade the psqlODBC to 08.02.0002 ,but the leak still
exists.

The piece of my Code is like this:
   SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
   SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
   SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);
   SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
   while( i < 10){
      SQLPrepare(hstmt,(SQLCHAR*)szSql, SQL_NTS);
      SQLBindParameter(......);
      ......
      SQLExecute(hstmt);
      SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
   }
   SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT);
   SQLFreeStmt(hstmt, SQL_CLOSE);
   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
   SQLDisconnect(hdbc);
   SQLFreeHandle(SQL_HANDLE_DBC, hdbc);

my Env: VC.net, windows2003 server, PostgreSQL8.1.3

some of you have faced similar issue for memory leak?
or I have made some misstake in Using the Odbc function?
If you could help me, that would be great!

thanks,
zhao






^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-09 11:20  Ludek Finstrle <luf@pzkagis.cz>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Ludek Finstrle @ 2006-06-09 11:20 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

>    SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
>    SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
>    SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);
>    SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
>    while( i < 10){
>       SQLPrepare(hstmt,(SQLCHAR*)szSql, SQL_NTS);
>       SQLBindParameter(......);
>       ......

Please could you send us the exact szSql and their BindParameters
so we don't have to make steps into dark? BTW table structure and
some sample data could help too.
It speeds up finding the problem.

>       SQLExecute(hstmt);
>       SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
>    }
>    SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT);
>    SQLFreeStmt(hstmt, SQL_CLOSE);
>    SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
>    SQLDisconnect(hdbc);
>    SQLFreeHandle(SQL_HANDLE_DBC, hdbc);

Regards,

Luf



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-14 11:40  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Ludek Finstrle <luf@pzkagis.cz>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-14 11:40 UTC (permalink / raw)
  To: pgsql-odbc

to:Luf

Thanks for you response.
my test program is below ,and I expect for you help .

Table structure:
*************************************
   CREATE TABLE TestLeak
   ( c1 int4,
     c2 text,
     c3 int4
    )
*************************************

my program is like this:
*************************************
void testInsert(){
     char *sqlInsert="insert into TestLeak values(?,?)";
     char szTmp[STR_LEN];//STR_LEN = 132
     SQLINTEGER  sOrderID=0 ,cbValue = SQL_NTS;	
     SQLINTEGER  cbOrderID = 0 ;
     int i;

     //initialize
     memset(szTmp,0,STR_LEN);
     memset(szTmp,'a',STR_LEN-1);//insert 'a'

     //INSERT
     for(i = 0 ; i < count ; i++)
     {
         retcode = SQLPrepare(hstmt,(SQLCHAR*)sqlInsert,SQL_NTS);
         SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
                SQL_C_SLONG,SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID);
         SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
                SQL_CHAR,STR_LEN, 0, &szTmp, 0, &cbValue);
         SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_SLONG,
                SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID);
         sOrderID = i;
         retcode = SQLExecute(hstmt);
         if( RC_NOTSUCCESSFUL(retcode))
         {
         	exit_nicely();
         }
     }
     retcode = SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
     SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT);
}
******************************************************************

thanks,
zhao

Ludek Finstrle wrote:
>>   SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
>>   SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
>>   SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);
>>   SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
>>   while( i < 10){
>>      SQLPrepare(hstmt,(SQLCHAR*)szSql, SQL_NTS);
>>      SQLBindParameter(......);
>>      ......
> 
> 
> Please could you send us the exact szSql and their BindParameters
> so we don't have to make steps into dark? BTW table structure and
> some sample data could help too.
> It speeds up finding the problem.
> 
> 
>>      SQLExecute(hstmt);
>>      SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
>>   }
>>   SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT);
>>   SQLFreeStmt(hstmt, SQL_CLOSE);
>>   SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
>>   SQLDisconnect(hdbc);
>>   SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
> 
> 
> Regards,
> 
> Luf
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 

-- 

以上、よろしくお願いいたします。
*******************************************
NEC-CAS 基盤ソフトウェア開発本部 第二開発部
         趙 新
E-mail:zhaox@necas.nec.com.cn
Telel :8-0086-22-425
外 線:(010)8233-4433-425
*******************************************



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-14 21:43  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-14 21:43 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> to:Luf
>
> Thanks for you response.
> my test program is below ,and I expect for you help .

Could you try the dll at
    http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
Recently I found a memory leak in some combination of connection
options.

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-15 10:11  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-15 10:11 UTC (permalink / raw)
  To: pgsql-odbc

TO: Hiroshi Inoue

> Could you try the dll at
>    http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
> Recently I found a memory leak in some combination of connection
> options.
I have tested the driver downloaded from this link .
but memory leak seems still exist .

regards,
zhao



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-15 13:00  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-15 13:00 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> TO: Hiroshi Inoue
>
>> Could you try the dll at
>>    http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
>> Recently I found a memory leak in some combination of connection
>> options.
> I have tested the driver downloaded from this link .
> but memory leak seems still exist .

Could you tell me your connection string ?

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 01:22  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 2 replies; 21+ messages in thread

From: zhaoxin @ 2006-06-16 01:22 UTC (permalink / raw)
  To: pgsql-odbc

TO:Hiroshi Inoue


>>> Could you try the dll at
>>>    http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
>>> Recently I found a memory leak in some combination of connection
>>> options.
>>
>> I have tested the driver downloaded from this link .
>> but memory leak seems still exist .
> 
> 
> Could you tell me your connection string ?

My connection string is like this (with ODBC default settings):

  SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);

  SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,
                  (SQLPOINTER)SQL_OV_ODBC3,SQL_IS_INTEGER);

  SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);

  SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);

  SQLConnect(hdbc,(SQLCHAR*)szDSN, (SQLSMALLINT)strlen(szDSN),
	    (SQLCHAR*)szUID, (SQLSMALLINT)strlen(szUID),
	    (SQLCHAR*)szAuthStr, (SQLSMALLINT)strlen(szAuthStr));

  SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 02:45  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  1 sibling, 0 replies; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-16 02:45 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> TO:Hiroshi Inoue
> 
> 
>>>> Could you try the dll at
>>>>    http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
>>>> Recently I found a memory leak in some combination of connection
>>>> options.
>>>
>>> I have tested the driver downloaded from this link .
>>> but memory leak seems still exist .
>>
>>
>> Could you tell me your connection string ?
> 
> My connection string is like this (with ODBC default settings):

Could you tell me the option settings concretely ?

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 08:08  Ludek Finstrle <luf@pzkagis.cz>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  1 sibling, 1 reply; 21+ messages in thread

From: Ludek Finstrle @ 2006-06-16 08:08 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

> >>>Could you try the dll at
> >>>   http://www.geocities.jp/inocchichichi/psqlodbc/index.html ?
> >>>Recently I found a memory leak in some combination of connection
> >>>options.
> >>
> >>I have tested the driver downloaded from this link .
> >>but memory leak seems still exist .
> >
> >
> >Could you tell me your connection string ?
> 
> My connection string is like this (with ODBC default settings):
> 
>  SQLConnect(hdbc,(SQLCHAR*)szDSN, (SQLSMALLINT)strlen(szDSN),
> 	    (SQLCHAR*)szUID, (SQLSMALLINT)strlen(szUID),
> 	    (SQLCHAR*)szAuthStr, (SQLSMALLINT)strlen(szAuthStr));

Hiroshi needs to know the value for szDSN.

Regards,

Luf



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 09:03  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Ludek Finstrle <luf@pzkagis.cz>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-16 09:03 UTC (permalink / raw)
  To: pgsql-odbc


>>>Could you tell me your connection string ?
>>
>>My connection string is like this (with ODBC default settings):
>>
>> SQLConnect(hdbc,(SQLCHAR*)szDSN, (SQLSMALLINT)strlen(szDSN),
>>	    (SQLCHAR*)szUID, (SQLSMALLINT)strlen(szUID),
>>	    (SQLCHAR*)szAuthStr, (SQLSMALLINT)strlen(szAuthStr));
> 
> 
> Hiroshi needs to know the value for szDSN.
> 
ok,I see .
my connection string is below:
***************************
char   szDSN[20];
char   szUID[20];
char   szAuthStr[20];
...
sprintf(szDSN,"postgre_8.02\0");
sprintf(szUID,"test\0");
sprintf(szAuthStr,"test\0");
...
***************************
is there some problem here ?




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 09:32  Ludek Finstrle <luf@pzkagis.cz>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Ludek Finstrle @ 2006-06-16 09:32 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

Fri, Jun 16, 2006 at 05:03:14PM +0800, zhaoxin wrote:
> my connection string is below:
> ***************************
> char   szDSN[20];
> char   szUID[20];
> char   szAuthStr[20];
> ...
> sprintf(szDSN,"postgre_8.02\0");
> sprintf(szUID,"test\0");
> sprintf(szAuthStr,"test\0");
> ...
> ***************************
> is there some problem here ?

I see no problem. We only want to simulate your situation.
We need to know the exact psqlODBC state.

Please could you send us mylog output?

Regards,

Luf



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 13:55  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Ludek Finstrle <luf@pzkagis.cz>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-16 13:55 UTC (permalink / raw)
  To: pgsql-odbc


> I see no problem. We only want to simulate your situation.
> We need to know the exact psqlODBC state.
> 
> Please could you send us mylog output?

I add the mylog file to the attachment .
I hope it is helpful .

> 
> Regards,
> 
> Luf
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match
> 

Attachments:

mylog_1372.log (text/plain, 534B) download [2784]globals.extra_systable_prefixes = 'dd_;' [2784]aszKey='DSN', value='postgre_8.02' [2784]copyAttributes: DSN='postgre_8.02',server='',dbase='',user='',passwd='xxxxx',port='',onlyread='',protocol='',conn_settings='',disallow_premature=-1) [2784]getDSNinfo: DSN=postgre_8.02 overwrite=0 [2784]globals.extra_systable_prefixes = 'dd_;' [2784]rollback_on_error=1 [2784]globals.extra_systable_prefixes = 'dd_;' [2784]calling getDSNdefaults [2784]checking libpq library [2784]hmodule=63100000 [2784]libpq_exist=1 [2784]DETACHING PROCESS
^ permalink raw reply [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-16 14:21  zhaoxin <zhaox@necas.nec.com.cn>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-16 14:21 UTC (permalink / raw)
  To: pgsql-odbc



zhaoxin wrote:
> 
>> I see no problem. We only want to simulate your situation.
>> We need to know the exact psqlODBC state.
>>
>> Please could you send us mylog output?
> 
> 
> I add the mylog file to the attachment .
> I hope it is helpful .

sorry , the file I sended maybe is incorrect.
send again .

Regards,
zhao

Attachments:

  mylog_1792.zip (application/octet-stream, 5.7K) download

^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 07:31  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-19 07:31 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> 
> 
> zhaoxin wrote:
>>
>>> I see no problem. We only want to simulate your situation.
>>> We need to know the exact psqlODBC state.
>>>
>>> Please could you send us mylog output?
>>
>>
>> I add the mylog file to the attachment .
>> I hope it is helpful .
> 
> sorry , the file I sended maybe is incorrect.
> send again .

Were the data inserted properly when the log was taken ?
Judging from the log, the application seems to have
finished in the middle(6-th data) of the execution.

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 08:08  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 21+ messages in thread

From: zhaoxin @ 2006-06-19 08:08 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

To:Hiroshi

> Were the data inserted properly when the log was taken ?
> Judging from the log, the application seems to have
> finished in the middle(6-th data) of the execution.
> 
sorry , mybe not properly .
My program is like this :
loop :
    connect db ;
    insert 10 reocrds ;
    commit;
    update this 10 records ;
    commit;
    delete this 10 records ;
    commit;
    disconnect db;
end loop;
the loop is not terminable.
and I interrupted the program unproperly and took the log.
but I am sure it have run over one loop.



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 08:59  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  0 siblings, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-19 08:59 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> To:Hiroshi
> 
>> Were the data inserted properly when the log was taken ?
>> Judging from the log, the application seems to have
>> finished in the middle(6-th data) of the execution.
>>
> sorry , mybe not properly .
> My program is like this :
> loop :
>    connect db ;
>    insert 10 reocrds ;
>    commit;
>    update this 10 records ;
>    commit;
>    delete this 10 records ;
>    commit;
>    disconnect db;
> end loop;
> the loop is not terminable.

Well what do you mean by *Memory Leak* ?
Does the memory usage grow while repeating the loop ?

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 09:29  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 2 replies; 21+ messages in thread

From: zhaoxin @ 2006-06-19 09:29 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

To:Hiroshi

> 
> Well what do you mean by *Memory Leak* ?
> Does the memory usage grow while repeating the loop ?
> 
yes , in my test , I found memory usage keep growing .
bwt I used windows performance tool.



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 09:47  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  1 sibling, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-19 09:47 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> To:Hiroshi
> 
>>
>> Well what do you mean by *Memory Leak* ?
>> Does the memory usage grow while repeating the loop ?
>>
> yes , in my test , I found memory usage keep growing .
> bwt I used windows performance tool.

I can't see the growth here with a similar test case.
Could you send me the test program(exe) ?

regards,
Hiroshi Inoue




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 10:16  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 0 replies; 21+ messages in thread

From: zhaoxin @ 2006-06-19 10:16 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

To:Hiroshi Inoue

> I can't see the growth here with a similar test case.
> Could you send me the test program(exe) ?
ok ,  I add my cpp file to the attachment .
I hope you can help me .thanks

Regards,
zhao

Attachments:

TestOdbc.cpp (text/plain, 6.0K) download #include <stdio.h> #include <string.h> #include <windows.h> #include <sql.h> #include <sqlext.h> #include <sqltypes.h> #include <odbcss.h> #include <process.h> #include <time.h> #define RC_SUCCESSFUL(rc) (((rc) == SQL_SUCCESS) || ((rc) == SQL_SUCCESS_WITH_INFO)) #define RC_NOTSUCCESSFUL(rc) (!(RC_SUCCESSFUL(rc))) SQLHENV henv = SQL_NULL_HENV; SQLHDBC hdbc = SQL_NULL_HDBC; SQLHSTMT hstmt= SQL_NULL_HSTMT; char szSqlState[SQL_MAX_MESSAGE_LENGTH], szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; #define MAXBUFLEN 255 #define TAB_LEN SQL_MAX_TABLE_NAME_LEN + 1 #define COL_LEN SQL_MAX_COLUMN_NAME_LEN + 1 #define STR_LEN 128 #define REM_LEN 254+1 #define BIG_DATA_LEN 1024 SQLCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH]; SQLINTEGER NativeError; SQLSMALLINT MsgLen; RETCODE retcode; char szDSN[20] ; char szUID[20] ; char szAuthStr[20] ; int count = 10, n , i; int iInterval; void exit_nicely(){ if( RC_NOTSUCCESSFUL(retcode) ) { SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, (SQLCHAR*)szSqlState, &NativeError,(SQLCHAR*)szErrorMsg, SQL_MAX_MESSAGE_LENGTH, &MsgLen); fprintf(stdout,"SqlState=%s, NativeError=%d, ErrorMsg=%s\n", szSqlState, NativeError, szErrorMsg); SQLExecDirect(hstmt , (SQLCHAR*)"ROLLBACK" , SQL_NTS); } //SQLExecDirect(hstmt , (SQLCHAR*)"ROLLBACK" , SQL_NTS); SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT); /* Clean up. */ SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); SQLDisconnect(hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc); SQLFreeHandle(SQL_HANDLE_ENV, henv); //getchar(); exit(1); } void initDBCon(){ // Allocate the ODBC Environment and save handle. retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv); // Let ODBC know this is an ODBC 3.0 application. retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER); // Allocate an ODBC connection handle and connect. retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); //Set Connect Attr retcode = SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); //Connect retcode = SQLConnect(hdbc,(SQLCHAR*)szDSN, (SQLSMALLINT)strlen(szDSN), (SQLCHAR*)szUID, (SQLSMALLINT)strlen(szUID), (SQLCHAR*)szAuthStr, (SQLSMALLINT)strlen(szAuthStr)); if( RC_NOTSUCCESSFUL(retcode) ) { exit_nicely(); } // Allocate statement handles and do ODBC processing. SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); return; } void freeDBCon(){ SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT); /* Clean up. */ SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeHandle(SQL_HANDLE_STMT, hstmt); SQLDisconnect(hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc); SQLFreeHandle(SQL_HANDLE_ENV, henv); return; } void testInsert() { char *sqlInsert="insert into TestLeak values(?,?,?)"; char szTmp[101]; SQLINTEGER sOrderID=0 , sOrderID1=0 , cbValue2 = SQL_NTS; SQLINTEGER cbOrderID = 0 , cbOrderID1 = 0; //SQLINTEGER cbData; int i; //initialize memset(szTmp,0,101); memset(szTmp,'a',10);//insert 'a' //INSERT for(i = 0 ; i < count ; i++) { retcode = SQLPrepare(hstmt, (SQLCHAR*)sqlInsert, SQL_NTS); SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID); SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,STR_LEN, 0, &szTmp, 0, &cbValue2); SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID); sOrderID = i; retcode = SQLExecute(hstmt); if( RC_NOTSUCCESSFUL(retcode) ) { exit_nicely(); } } //retcode = SQLFreeStmt(hstmt,SQL_RESET_PARAMS); SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT); } void testUpdate() { char *sqlUpdate="update TestLeak set c2 = ? where c1 = ?"; char szTmp[101]; SQLINTEGER sOrderID=0 , sOrderID1=0 , cbValue2 = SQL_NTS; SQLINTEGER cbOrderID = 0 , cbOrderID1 = 0; int i; //initialize memset(szTmp,0,101); memset(szTmp,'b',10);//update to 'b' //Update for(i = 0 ; i < count ; i++) { retcode = SQLPrepare(hstmt, (SQLCHAR*)sqlUpdate, SQL_NTS); SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,STR_LEN, 0, &szTmp, 0, &cbValue2); SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID); //SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID); sOrderID = i; retcode = SQLExecute(hstmt); if( RC_NOTSUCCESSFUL(retcode) ) { exit_nicely(); } } SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT); } void testDelete() { char *sqlDelete="DELETE from TestLeak where c1 = ?"; //char szTmp[101]; SQLINTEGER sOrderID=0 , sOrderID1=0; SQLINTEGER cbOrderID = 0 , cbOrderID1 = 0; int i; //Delete for(i = 0 ; i < count ; i++) { retcode = SQLPrepare(hstmt, (SQLCHAR*)sqlDelete, SQL_NTS); SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &sOrderID, 0, &cbOrderID); sOrderID = i; retcode = SQLExecute(hstmt); if( RC_NOTSUCCESSFUL(retcode) ) { exit_nicely(); } } SQLEndTran(SQL_HANDLE_DBC,(SQLHDBC)hdbc, SQL_COMMIT); } int main(int argc, char *argv[] ) { int m = 1; if( argc == 1 ){//default sprintf(szDSN,"postgre_8.02\0"); sprintf(szUID,"postgres\0"); sprintf(szAuthStr,"postgres\0"); iInterval = 1; }else if( argc == 5 ){ sprintf(szDSN,argv[1]);//DSN sprintf(szUID,argv[2]);//User sprintf(szAuthStr,argv[3]);//Password iInterval = atoi(argv[4]);//Interval }else{ fprintf(stdout,"invalid args!\n"); fprintf(stdout,"Usage: testODBC.exe <DSN> <User> <Password> <Interval>"); return(0); } //----test begin----- while(true){ fprintf(stdout,"connect....\n"); initDBCon(); fprintf(stdout,"insert....\n"); testInsert(); fprintf(stdout,"update....\n"); testUpdate(); fprintf(stdout,"delete....\n"); testDelete(); Sleep(1*1000); fprintf(stdout,"free....\n"); freeDBCon(); } //----test end----- exit_nicely(); }
^ permalink raw reply [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-19 13:55  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: zhaoxin <zhaox@necas.nec.com.cn>
  1 sibling, 1 reply; 21+ messages in thread

From: Hiroshi Inoue @ 2006-06-19 13:55 UTC (permalink / raw)
  To: zhaoxin <zhaox@necas.nec.com.cn>; +Cc: pgsql-odbc

zhaoxin wrote:
> To: Hiroshi
>
>>
>> Well what do you mean by *Memory Leak* ?
>> Does the memory usage grow while repeating the loop ?
>>
> yes , in my test , I found memory usage keep growing .
>

How many bytes does it grow per the loop ?

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: Memory Leak ?
@ 2006-06-20 01:12  zhaoxin <zhaox@necas.nec.com.cn>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 0 replies; 21+ messages in thread

From: zhaoxin @ 2006-06-20 01:12 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc


>>>
>>> Well what do you mean by *Memory Leak* ?
>>> Does the memory usage grow while repeating the loop ?
>>>
>> yes , in my test , I found memory usage keep growing .
>>
> 
> How many bytes does it grow per the loop ?
> 
I found it grows about 1k bytes  per the loop.
In my test , the prgram loop about 30-40 times in one minute ,
and I founded 30-40K growth in one minute .
so , I think it leaks about 1k per the loop . is it right ?

regards,
zhao



^ permalink  raw  reply  [nested|flat] 21+ messages in thread


end of thread, other threads:[~2006-06-20 01:12 UTC | newest]

Thread overview: 21+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-08 09:01 Memory Leak ? zhaoxin <zhaox@necas.nec.com.cn>
2006-06-09 11:20 ` Ludek Finstrle <luf@pzkagis.cz>
2006-06-14 11:40   ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-14 21:43     ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-15 10:11       ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-15 13:00         ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-16 01:22           ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-16 02:45             ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-16 08:08             ` Ludek Finstrle <luf@pzkagis.cz>
2006-06-16 09:03               ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-16 09:32                 ` Ludek Finstrle <luf@pzkagis.cz>
2006-06-16 13:55                   ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-16 14:21                     ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-19 07:31                       ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-19 08:08                         ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-19 08:59                           ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-19 09:29                             ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-19 09:47                               ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-19 10:16                                 ` zhaoxin <zhaox@necas.nec.com.cn>
2006-06-19 13:55                               ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-20 01:12                                 ` zhaoxin <zhaox@necas.nec.com.cn>

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