Memory Leak when Fetching Blob via ODBC
Posted in 1998
Topics: Installation, Setup & Upgrades, Connectivity: ODBC / JDBC / .NET, Security, Permissions & Auditing
This is a multi-part message in MIME format. --------------8AD181E0C0F35C385FB003E8 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, I have a huge memory problem. I wrote a simple C program that connects to a Informix DB via ODBC. The ODBC-Driver is from Intersolv. Now, every time I make SQLFetch, my program uses more memory. Unfortuneately SQLFreeStmt does not free up all used memory. I have this memory leak also with other ODBC-Driver, but only when fetching blobs. Has someone similar Problems? Is this a know Problem? How can I free up the memory myself? Does someon know the structure of the memspace where blobs are stored? any help would be great Patrick Dittich Akros AG System: Client: Windows NT Workstation 4.0 SP3, MS-VisualC 5.0 ent.edt. SP3 / Intersolv ODBC-Driver for Informix (INTERSOLV 3.01 32-BIT INFORMIX V 3.01.0000) Informix Connect 7.2 Server: Infomix 7.12 on AIX -------8<---------------------8<-----------------------8<------------------------ /* odbctest.c */ /* use this if you have installed ODBC 3.0 and want to use an older Version */ /*#define ODBCVER 0x0250 */ #include <stdio.h> #include <windows.h> #include <sqlext.h> #include <sql.h> FILE *stream; int x; char filename[1023]; HENV henv; HDBC hdbc; HSTMT hstmt; RETCODE retcd; UCHAR szName[511]; UCHAR szBlob[15000]; SWORD iSerial; SDWORD cbName, cbBlob, cbSerial; void main () { retcd = SQLAllocEnv(&henv); /* Environment handle */ if (retcd == SQL_SUCCESS) { retcd = SQLAllocConnect(henv, &hdbc); /* Connection handle */ if (retcd == SQL_SUCCESS) { /* Set login timeout to 25 seconds. */ SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 25); /* Connect to data source */ retcd = SQLConnect(hdbc, "yourdsn", SQL_NTS, "username", SQL_NTS, "password", SQL_NTS); if (retcd == SQL_SUCCESS || retcd == SQL_SUCCESS_WITH_INFO){ printf("Connected\\n"); /* Process data after successful connection */ retcd = SQLAllocStmt(hdbc, &hstmt); /* Statement handle */ if (retcd == SQL_SUCCESS) { /*SQLSelect*/ retcd = SQLExecDirect(hstmt, "SELECT * FROM akr_blobtest where image_id = 10", SQL_NTS); if (retcd == SQL_SUCCESS) { while (TRUE) { /**************************************************************/ retcd = SQLFetch(hstmt); /* HERE THE MEMORY LEAK OCCURES */ /**************************************************************/ if (retcd == SQL_ERROR || retcd == SQL_SUCCESS_WITH_INFO) { printf("Error from SQLFetch\\n"); } if (retcd == SQL_SUCCESS || retcd == SQL_SUCCESS_WITH_INFO){ /* Get data for columns 1,2 and 3 */ SQLGetData(hstmt, 1, SQL_INTEGER, &iSerial, 0, &cbSerial); SQLGetData(hstmt, 2, SQL_C_CHAR, szName, 511, &cbName); SQLGetData(hstmt, 3, SQL_C_BINARY, szBlob, 15000, &cbBlob); /* Print the row of data */ printf("Result:\\n"); printf("%i, %s Size:%i\\n",iSerial, szName, cbBlob); strcpy(filename,"c:\\\\tempfile.tif"); if( (stream = fopen( filename, "wb" )) == NULL ) { printf( "The file %s was not opened\\n",filename ); return; } for (x=0;x<cbBlob;x++) { fputc((unsigned) szBlob[x],stream); printf("%i\\n",x); } fclose(stream); } else { printf("No resultset\\n"); break; } } } /**********************************************************************/ SQLFreeStmt(hstmt, SQL_DROP); /* THIS DOES NOT FREE UP ALL USED MEM*/ /**********************************************************************/ } SQLDisconnect(hdbc); } SQLFreeConnect(hdbc); } SQLFreeEnv(henv); } return; } --------------8AD181E0C0F35C385FB003E8 Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Patrick Dittrich Content-Disposition: attachment; filename="vcard.vcf" begin: vcard fn: Patrick Dittrich n: Dittrich;Patrick org: Akros AG adr: Lyss-Strasse 64;;;Nidau;BE;2560;Switzerland email;internet: dittrich@akros.ch title: Softwareengineer tel;work: ++41/(0)32 329 90 55 tel;fax: ++41/(0)32 329 90 35 tel;home: ++41/(0)32 365 77 49 note: Ein nettes "Hallo" an den Leser dieser Notiz x-mozilla-cpt: ;0 x-mozilla-html: TRUE version: 2.1 end: vcard --------------8AD181E0C0F35C385FB003E8--