Still some Memory leaks using Informix SE 5.0
Posted in 1995
Topics: High Availability & Replication, Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL
As we describe in a previous message, we encounter some memory leaks using Informix SE on several servers (Sun SunOS 4.1.3, HP HP/UX 9.04) on a program written in ESQL/C. We got several memory leaks : some memory leaks of 10 bytes, 11 bytes, 64 bytes and 1024 bytes. We got responses that help us to suppress the leaks of 10, 11 and 1024 bytes (thanks to Jonathan Leffler,johnl@informix.com, Frank Bonk,bonk@positron.med.ge.com and Sanjay Kumar,SOHO!dpsanjay@whitestone.raileurope.com) : we must FREE the cursor (sqlcurs in our example). But we still have a remaining memory leak of 64 bytes each time we (the size of the _SQCURSOR internal structure of ESQL/C). This structure is describe in the header sqlhdr.h in $INFORMIXDIR/incl/esql. Here is our memory leak : 64 bytes (5 times) = 320 total bytes. _sqrealloc (iqutil.o) _iqnormdesc (iqdynam.o) _iqdescribe (iqdynam.o) testinf (esql.o) main (main.o) start (usr_lib_crt0.o) The problem comes from the EXEC SQL describe, if we suppress this statment, the problem there is no memory leak. Here is the last version of our test program : /*******************************************************************/ #include <stdio.h> EXEC SQL INCLUDE sqlca; EXEC SQL INCLUDE sqlda; /* ** Handle SQL errors */ void my_handle_error() { fprintf( stderr, "sqlcode=%d\\n", sqlca.sqlcode ); exit( 1 ); } /* ** Prepare, describe, declare a cursor for a select. ** You can put any select in the parameter. ** We you call several times this function, you loose some ** memory (about 1 Ko each time). */ void testinf( q_string ) EXEC SQL BEGIN DECLARE SECTION; char *q_string; EXEC SQL END DECLARE SECTION; { struct SQLDA *q_desc; EXEC SQL prepare sqlobj from $q_string; if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL describe sqlobj into q_desc; if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL declare sqlcurs cursor with hold for sqlobj; if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL open sqlcurs; if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL close sqlcurs; if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL free sqlcurs; /* <- We add this line to suppress some of the memory leaks */ if(sqlca.sqlcode<0) my_handle_error(); EXEC SQL free sqlobj; if(sqlca.sqlcode<0) my_handle_error(); } /* ** Here is the main function of our program. ** It calls 5 times the function that create the cursor for the select. */ main() { int i; EXEC SQL database our_database; /* <- put there the name of your database */ for( i = 0; i < 5; i++ ) testinf( "select count(*) from adresses" ); exit( 0 ); } /***********************************************************************/ If you have seen this problem somewhere or if you have a idea to solve this problem that would be great. Thanks in advance. Roger FLATTIN CORNUT Informatique +------------------------------------+--------------------------+ | Roger Flattin | Phone : (33) 77 93 57 46 | | Cornut Informatique | Fax : (33) 77 92 51 39 | | 24, rue de la Telematique - BP 702 | AppleLink : CORNUT.INF | | 42950 St Etienne cedex 9 FRANCE | Compuserve: 100303,1061 | | frederic_bouquet@ascus.com | | +------------------------------------+--------------------------+