Hi All,
Below is the code of my sample application.
main() {
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret; /* ODBC API return status
*/
SQLCHAR outstr[1024] = {0};
SQLSMALLINT outstrlen;
unsigned long loop = 0;
/* Allocate an environment handle */
SQLAllocHandle(SQL_HANDLE_ENV,
SQL_NULL_HANDLE, &env);
/* We want ODBC 3 support */
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION,
(void *) SQL_OV_ODBC3, 0);
/* Allocate a connection handle */
SQLAllocHandle(SQL_HANDLE_DBC, env,
&dbc);
/* Connect */
ret = SQLDriverConnect(dbc, NULL,
"SERVERNAME=127.0.0.1;DSN=xsw;DATABASE=xsw;UID=xsw",
strlen("SERVERNAME=127.0.0.1;DSN=xsw;DATABASE=xsw;UID=xsw"),
outstr,
sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(ret)) {
printf("Connected\n");
printf("Returned
connection string was:\n\t%s\n", outstr);
if (ret ==
SQL_SUCCESS_WITH_INFO) {
printf("Driver
reported the following diagnostics\n");
}
SQLDisconnect(dbc);
/* disconnect from driver */
} else {
fprintf(stderr,
"Failed to connect\n");
}
/* free up allocated handles */
SQLFreeHandle(SQL_HANDLE_DBC, dbc);
SQLFreeHandle(SQL_HANDLE_ENV, env);
return 0;
}
When I run this application (with connection pooling enabled)
with valgrind then it shows some memory leaks in SQLDriverConnect().
Below is the snippet of the valgrind output where it shows
memory leaks.
==2862== 32,840 (80 direct, 32,760 indirect) bytes in 1
blocks are definitely lost in loss record 45 of 69
==2862== at 0x401B85E: malloc
(vg_replace_malloc.c:149)
==2862== by 0x409C159: __gconv_open (in
/lib/tls/libc.so.6)
==2862== by 0x409BDF4: iconv_open (in
/lib/tls/libc.so.6)
==2862== by 0x406AF70: unicode_setup
(__info.c:534)
==2862== by 0x403268D: __connect_part_one
(SQLConnect.c:971)
==2862== by 0x40379C8: SQLDriverConnect
(SQLDriverConnect.c:1118)
==2862== by 0x8048629: main (test.c:24)
==2862==
==2862==
==2862== 32,840 (80 direct, 32,760 indirect) bytes in 1
blocks are definitely lost in loss record 48 of 69
==2862== at 0x401B85E: malloc
(vg_replace_malloc.c:149)
==2862== by 0x409C159: __gconv_open (in
/lib/tls/libc.so.6)
==2862== by 0x409BDF4: iconv_open (in
/lib/tls/libc.so.6)
==2862== by 0x406AF91: unicode_setup
(__info.c:535)
==2862== by 0x403268D: __connect_part_one
(SQLConnect.c:971)
==2862== by 0x40379C8: SQLDriverConnect
(SQLDriverConnect.c:1118)
==2862== by 0x8048629: main (test.c:24)
Seems to me that iconv_close() is not getting called when I
disconnect using SQLDisconnect().
Am I doing something wrong or is this a problem with unix
odbc library?
Thanks & Regards,
Siddarth
PS: I am connecting to Postgres DB