Hello all,

I wrote a small test program that calls sqleatin and sqledtin. The program leaks linearly based on this formula 446.8 + Iteration * 11/27. Attached is the sample program and I really appreciate if someone can confirm this on their environment. My environment is UDB v7.2 with FP3 on AIX 5.1L. My sample runs produced the following results:

Iteration Memory Leak
====== =========
3 448K
30 459K
300 564K


Regards,
Sam.



/** Sample code begins here **/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlenv.h>
#include <malloc.h>
#include <unistd.h>

#define CHECK_NULL(p) ((p == NULL) || (*p == '\0'))

#define MO_ERR -1
#define MO_INFO -2
#define LOOP 3 // 30, 300 etc
#define MAX_LINE 256
#define DB2INSTANCE "DB2INSTANCE"

static char g_cErrMsg[1024];
static char instbuf[256];


/*******************************************
* *
*******************************************/
int main()
{
int i, rc = 0;
struct sqlca m_sqlca;

char *db2inst_env = NULL;
struct mallinfo a, b;
double heapsz = 0.0f, memdiff = 0.0f;

db2inst_env = getenv(DB2INSTANCE);
if (CHECK_NULL(db2inst_env)) {
memset (instbuf, 0, sizeof(instbuf));
sprintf(instbuf, "%s=%s", DB2INSTANCE, "nisinst1");
rc = putenv(instbuf);
if (rc != 0) {
printf("Failed to setenv DB2INSTANCE\n");
return -1;
}
}

b = mallinfo(); // get memory snapshot before calling DB2 API

for (i = 0; i < LOOP; i++) {
/* connect to the instance */
sqleatin("nisinst1", "nisinst1", "somepassword", &m_sqlca);
if (m_sqlca.sqlcode != SQL_RC_OK) {
sqlaintp(g_cErrMsg, sizeof(g_cErrMsg), MAX_LINE, &m_sqlca);
printf("Error: sqleatin - %s\n", g_cErrMsg);
rc = MO_ERR;
goto out;
}
sqledtin(&m_sqlca);
}

a = mallinfo(); // get memory snapshot after calling DB2 API

// free DB2INSTANCE env
memset (instbuf, 0, sizeof(instbuf));
sprintf(instbuf, "%s=", DB2INSTANCE);
putenv(instbuf);

// calc memory statistics & print out results
heapsz = (double) (a.arena - b.arena) / (double) SQL_KILO_VALUE;
memdiff = (double)((a.usmblks + a.uordblks) - (b.usmblks + b.uordblks)) / (double) SQL_KILO_VALUE;
printf("Heap size difference is %.2f KB\n", heapsz);
printf("Memory in use difference = %.2f KB\n", memdiff);

out:

return rc;
}