Arrgh....Why does this little C++ program leak' memory ?
- From: "LTDEV" <nos@xxxxxx>
- Date: Wed, 24 Jan 2007 22:03:09 +0100
Doing a simple stress-test with the program below, it just adds records to
the table until i press ESC.
Monitoring it with taskmanager, i can see it leaks bigtime - what am i doing
wrong ? (data is inserted correctly and all).
Hope you can help to tell me how i can use the following code and NOT get a
leak, thanks.
----------
#include <windows.h>
#include <SQL.H>
#include <SQLEXT.H>
#include <stdio.h>
#include <conio.h>
int main(int argc, char* argv[])
{
printf("Repeat stuffing data into database\n");
RETCODE rcode, rcodeinfo;
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SDWORD sdODataLength;
unsigned char buffer[256];
char ch=0x00;
char szDBNameO8[] = "db_fb_test";
char szUsername[] = "sysdba";
char szPassword[] = "masterkey";
while (ch!=0x1b) // loop until you press ESC
{
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)
SQL_OV_ODBC3, SQL_IS_INTEGER);
rcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
rcode = SQLDriverConnect(hdbc, 0, (unsigned
char*)"DSN=FBtest;UID=sysdba;PWD=masterkey", SQL_NTS, buffer, 256, NULL,
SQL_DRIVER_NOPROMPT);
SWORD len;
char CurrentUser[10];
rcodeinfo = SQLGetInfo(hdbc, SQL_USER_NAME, CurrentUser,
sizeof(CurrentUser), &len);
buffer[0]=0x00;
char szTemp[2048];
rcode = SQLAllocStmt(hdbc, &hstmt);
if (rcode == SQL_SUCCESS || rcode == SQL_SUCCESS_WITH_INFO)
{
sprintf (szTemp,"INSERT INTO PACKDATABASE VALUES (1,%u,'test')",1);
SQLPrepare(hstmt, szTemp, SQL_NTS);
SQLExecute(hstmt);
}
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
if (kbhit())
ch=getch();
}
}
.
- Follow-Ups:
- Prev by Date: SQL_HANDLE_ENV failed
- Next by Date: Re: Arrgh....Why does this little C++ program leak' memory ?
- Previous by thread: SQL_HANDLE_ENV failed
- Next by thread: Re: Arrgh....Why does this little C++ program leak' memory ?
- Index(es):